JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> if (jp.getCurrentToken() == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final T value = deserialize(jp, ctxt);
if (jp.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single '" + _valueClass.getName() + "' value but there was more than a single value in the array");
}
return value;
}
// 22-Sep-2012, tatu: For 2.1, use this new method, may force coercion:
String text = jp.getValueAsString();
if (text != null) { // has String representation
if (text.length() == 0 || (text = text.trim()).length() == 0) {
// 04-Feb-2013, tatu: Usually should become null; but not always
return _deserializeFromEmptyString();
}
Exception cause = null;
try {
T result = _deserialize(text, ctxt);
if (result != null) {
return result;
}
} catch (IllegalArgumentException iae) {
cause = iae;
}
String msg = "not a valid textual representation";
if (cause != null) {
String m2 = cause.getMessage();
if (m2 != null) {
msg = msg + ", problem: "+m2;
}
}
JsonMappingException e = ctxt.weirdStringException(text, _valueClass, msg);
if (cause != null) {
e.initCause(cause);
}
throw e;
// nothing to do here, yet? We'll fail anyway
}
if (jp.getCurrentToken() == JsonToken.VALUE_EMBEDDED_OBJECT) {
// Trivial cases; null to null, instance of type itself returned as is
Object ob = jp.getEmbeddedObject();
if (ob == null) {
return null;
}
if (_valueClass.isAssignableFrom(ob.getClass())) {
return (T) ob;
}
return _deserializeEmbedded(ob, ctxt);
}
throw ctxt.mappingException(_valueClass);
}
protected abstract T _deserialize(String value, DeserializationContext ctxt) throws IOException;
protected T _deserializeEmbedded(Object ob, DeserializationContext ctxt) throws IOException {
// default impl: error out
throw ctxt.mappingException("Don't know how to convert embedded Object of type %s into %s",
ob.getClass().getName(), _valueClass.getName());
}
protected T _deserializeFromEmptyString() throws IOException {
return null;
}
/*
/**********************************************************
/* A general-purpose implementation
/**********************************************************
*/
/**
* "Chameleon" deserializer that works on simple types that are deserialized
* from a simple String.
*
* @since 2.4
*/
public static class Std extends FromStringDeserializer<Object>
{
private static final long serialVersionUID = 1;
public final static int STD_FILE = 1;
public final static int STD_URL = 2;
public final static int STD_URI = 3;
public final static int STD_CLASS = 4;
public final static int STD_JAVA_TYPE = 5;
public final static int STD_CURRENCY = 6;
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.lang.reflect.Method;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.CompactStringObjectMap;
import com.fasterxml.jackson.databind.util.EnumResolver;
/**
* Deserializer class that can deserialize instances of
* specified Enum class from Strings and Integers.
*/
@JacksonStdImpl // was missing until 2.6
public class EnumDeserializer
extends StdScalarDeserializer<Object>
{
private static final long serialVersionUID = 1L;
/**
* @since 2.6
*/
protected final CompactStringObjectMap _enumLookup;
/**
* @since 2.6
*/
protected Object[] _enumsByIndex;
public EnumDeserializer(EnumResolver res)
{
super(res.getEnumClass());
_enumLookup = res.constructLookup();
_enumsByIndex = res.getRawEnums();
}
/**
* Factory method used when Enum instances are to be deserialized
* using a creator (static factory method)
*
* @return Deserializer based on given factory method, if type was suitable;
* null if type can not be used
*/
public static JsonDeserializer<?> deserializerForCreator(DeserializationConfig config,
Class<?> enumClass, AnnotatedMethod factory)
{
// note: caller has verified there's just one arg; but we must verify its type
Class<?> paramClass = factory.getRawParameterType(0);
if (config.canOverrideAccessModifiers()) {
ClassUtil.checkAndFixAccess(factory.getMember());
}
return new FactoryBasedDeserializer(enumClass, factory, paramClass);
}
/*
/**********************************************************
/* Default JsonDeserializer implementation
/**********************************************************
*/
/**
* Because of costs associated with constructing Enum resolvers,
* let's cache instances by default.
*/
@Override
public boolean isCachable() { return true; }
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
JsonToken curr = p.getCurrentToken();
// Usually should just get string value:
if (curr == JsonToken.VALUE_STRING || curr == JsonToken.FIELD_NAME) {
String name = p.getText();
Object result = _enumLookup.find(name);
if (result == null) {
return _deserializeAltString(p, ctxt, name);
}
return result;
}
// But let's consider int acceptable as well (if within ordinal range)
if (curr == JsonToken.VALUE_NUMBER_INT) {
// ... unless told not to do that. :-) (as per [JACKSON-412])
_checkFailOnNumber(ctxt);
int index = p.getIntValue();
if (index >= 0 && index <= _enumsByIndex.length) {
return _enumsByIndex[index];
}
if (!ctxt.isEnabled(DeserializationFeature.READ_UNKNOWN
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>_ENUM_VALUES_AS_NULL)) {
throw ctxt.weirdNumberException(Integer.valueOf(index), _enumClass(),
"index value outside legal index range [0.."+(_enumsByIndex.length-1)+"]");
}
return null;
}
return _deserializeOther(p, ctxt);
}
private final Object _deserializeAltString(JsonParser p, DeserializationContext ctxt,
String name) throws IOException
{
name = name.trim();
if (name.length() == 0) {
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
return null;
}
} else {
// [#149]: Allow use of 'String' indexes as well
char c = name.charAt(0);
if (c >= '0' && c <= '9') {
try {
int ix = Integer.parseInt(name);
_checkFailOnNumber(ctxt);
if (ix >= 0 && ix <= _enumsByIndex.length) {
return _enumsByIndex[ix];
}
} catch (NumberFormatException e) {
// fine, ignore, was not an integer
}
}
}
if (!ctxt.isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
throw ctxt.weirdStringException(name, _enumClass(),
"value not one of declared Enum instance names: "+_enumLookup.keys());
}
return null;
}
protected Object _deserializeOther(JsonParser p, DeserializationContext ctxt) throws IOException
{
JsonToken curr = p.getCurrentToken();
// [databind#381]
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)
&& p.isExpectedStartArrayToken()) {
p.nextToken();
final Object parsed = deserialize(p, ctxt);
curr = p.nextToken();
if (curr != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single '" + _enumClass().getName() + "' value but there was more than a single value in the array");
}
return parsed;
}
throw ctxt.mappingException(_enumClass());
}
protected void _checkFailOnNumber(DeserializationContext ctxt) throws IOException
{
if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS)) {
throw ctxt.mappingException("Not allowed to deserialize Enum value out of JSON number (disable DeserializationConfig.DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS to allow)");
}
}
protected Class<?> _enumClass() {
return handledType();
}
/*
/**********************************************************
/* Additional helper classes
/**********************************************************
*/
/**
* Deserializer that uses a single-String static factory method
* for locating Enum values by String id.
*/
protected static class FactoryBasedDeserializer
extends StdDeserializer<Object>
implements ContextualDeserializer
{
private static final long serialVersionUID = 1;
// Marker type; null if String expected; otherwise numeric wrapper
protected final Class<?> _inputType;
protected final Method _factory;
protected final JsonDeserializer<?> _deser;
public FactoryBasedDeserializer(Class<?> cls, AnnotatedMethod f,
Class<?> inputType)
{
super(cls);
_factory = f.getAnnotated();
_input
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>Type = inputType;
_deser = null;
}
protected FactoryBasedDeserializer(FactoryBasedDeserializer base,
JsonDeserializer<?> deser) {
super(base._valueClass);
_inputType = base._inputType;
_factory = base._factory;
_deser = deser;
}
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property)
throws JsonMappingException
{
if ((_deser == null) && (_inputType != String.class)) {
return new FactoryBasedDeserializer(this,
ctxt.findContextualValueDeserializer(ctxt.constructType(_inputType), property));
}
return this;
}
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
Object value;
if (_deser != null) {
value = _deser.deserialize(p, ctxt);
} else {
JsonToken curr = p.getCurrentToken();
if (curr == JsonToken.VALUE_STRING || curr == JsonToken.FIELD_NAME) {
value = p.getText();
} else {
value = p.getValueAsString();
}
}
try {
return _factory.invoke(_valueClass, value);
} catch (Exception e) {
Throwable t = ClassUtil.getRootCause(e);
if (t instanceof IOException) {
throw (IOException) t;
}
throw ctxt.instantiationException(_valueClass, t);
}
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException {
if (_deser == null) { // String never has type info
return deserialize(p, ctxt);
}
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
}
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
/**
* Intermediate base class for serializers used for serializing
* types that contain element(s) of other types, such as arrays,
* {@link java.util.Collection}s (<code>Lists</code>, <code>Sets</code>
* etc) and {@link java.util.Map}s and iterable things
* ({@link java.util.Iterator}s).
*/
@SuppressWarnings("serial")
public abstract class ContainerSerializer<T>
extends StdSerializer<T>
{
/*
/**********************************************************
/* Construction, initialization
/**********************************************************
*/
protected ContainerSerializer(Class<T> t) {
super(t);
}
/**
* @since 2.5
*/
protected ContainerSerializer(JavaType fullType) {
super(fullType);
}
/**
* Alternate constructor that is (alas!) needed to work
* around kinks of generic type handling
*
* @param t
*/
protected ContainerSerializer(Class<?> t, boolean dummy) {
super(t, dummy);
}
protected ContainerSerializer(ContainerSerializer<?> src) {
super(src._handledType, false);
}
/**
* Factory(-like) method that can be used to construct a new container
* serializer that uses specified {@link TypeSerializer} for decorating
* contained values with additional type information.
*
* @param vts Type serializer to use for contained values; can be null,
* in which case 'this' serializer is returned as is
* @return Serializer instance that uses given type serializer for values if
* that is possible (or if not, just 'this' serializer)
*/
public ContainerSerializer<?> withValueTypeSerializer(TypeSerializer vts) {
if (vts == null) return this;
return _withValueTypeSerializer(vts);
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Accessor for finding declared (static) element type for
* type this serializer is used for.
*/
public abstract JavaType getContentType();
/**
* Accessor for serializer used for serializing contents
* (List and array elements, Map values etc) of the
* container for which this serializer is used, if it is
* known statically.
* Note that for dynamic types this may return null; if so,
* caller has to instead use {@link #getContentType()} and
* {@link com.fasterxml.jackson.databind.SerializerProvider#findValueSerializer}.
*/
public abstract JsonSerializer<?> getContentSerializer();
/*
/**********************************************************
/* Abstract methods for sub-classes to implement
/**********************************************************
*/
/* Overridden as abstract, to force re-implementation; necessary for all
* collection types.
*/
@Override
@Deprecated
public boolean isEmpty(T value) {
return isEmpty(null, value);
}
// since 2.5: should be declared abstract in future (2.6)
// @Override
// public abstract boolean isEmpty(SerializerProvider prov, T value);
/**
* Method called to determine if the given value (of type handled by
* this serializer) contains exactly
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import java.util.*;
import com.fasterxml.jackson.databind.JavaType;
/**
* Simple recursive-descent parser for parsing canonical {@link JavaType}
* representations and constructing type instances.
*
* @author tatu
*/
public class TypeParser
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected final TypeFactory _factory;
public TypeParser(TypeFactory f) {
_factory = f;
}
/**
* @since 2.6.2
*/
public TypeParser withFactory(TypeFactory f) {
return (f == _factory) ? this : new TypeParser(f);
}
public JavaType parse(String canonical)
throws IllegalArgumentException
{
canonical = canonical.trim();
MyTokenizer tokens = new MyTokenizer(canonical);
JavaType type = parseType(tokens);
// must be end, now
if (tokens.hasMoreTokens()) {
throw _problem(tokens, "Unexpected tokens after complete type");
}
return type;
}
protected JavaType parseType(MyTokenizer tokens)
throws IllegalArgumentException
{
if (!tokens.hasMoreTokens()) {
throw _problem(tokens, "Unexpected end-of-string");
}
Class<?> base = findClass(tokens.nextToken(), tokens);
// either end (ok, non generic type), or generics
if (tokens.hasMoreTokens()) {
String token = tokens.nextToken();
if ("<".equals(token)) {
return _factory._fromParameterizedClass(base, parseTypes(tokens));
}
// can be comma that separates types, or closing '>'
tokens.pushBack(token);
}
return _factory._fromClass(base, null);
}
protected List<JavaType> parseTypes(MyTokenizer tokens)
throws IllegalArgumentException
{
ArrayList<JavaType> types = new ArrayList<JavaType>();
while (tokens.hasMoreTokens()) {
types.add(parseType(tokens));
if (!tokens.hasMoreTokens()) break;
String token = tokens.nextToken();
if (">".equals(token)) return types;
if (!",".equals(token)) {
throw _problem(tokens, "Unexpected token '"+token+"', expected ',' or '>')");
}
}
throw _problem(tokens, "Unexpected end-of-string");
}
protected Class<?> findClass(String className, MyTokenizer tokens)
{
try {
return _factory.findClass(className);
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw _problem(tokens, "Can not locate class '"+className+"', problem: "+e.getMessage());
}
}
protected IllegalArgumentException _problem(MyTokenizer tokens, String msg)
{
return new IllegalArgumentException("Failed to parse type '"+tokens.getAllInput()
+"' (remaining: '"+tokens.getRemainingInput()+"'): "+msg);
}
final static class MyTokenizer
extends StringTokenizer
{
protected final String _input;
protected int _index;
protected String _pushbackToken;
public MyTokenizer(String str) {
super(str, "<,>", true);
_input = str;
}
@Override
public boolean hasMoreTokens() {
return (_pushbackToken != null) || super.hasMoreTokens();
}
@Override
public String nextToken() {
String token
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>;
if (_pushbackToken != null) {
token = _pushbackToken;
_pushbackToken = null;
} else {
token = super.nextToken();
}
_index += token.length();
return token;
}
public void pushBack(String token) {
_pushbackToken = token;
_index -= token.length();
}
public String getAllInput() { return _input; }
public String getUsedInput() { return _input.substring(0, _index); }
public String getRemainingInput() { return _input.substring(_index); }
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> bindingsForBeanType()
{
if (_bindings == null) {
_bindings = new TypeBindings(_config.getTypeFactory(), _type);
}
return _bindings;
}
@Override
public JavaType resolveType(java.lang.reflect.Type jdkType) {
if (jdkType == null) {
return null;
}
return bindingsForBeanType().resolveType(jdkType);
}
@Override
public AnnotatedConstructor findDefaultConstructor() {
return _classInfo.getDefaultConstructor();
}
@Override
public AnnotatedMethod findAnySetter() throws IllegalArgumentException
{
AnnotatedMethod anySetter = (_propCollector == null) ? null
: _propCollector.getAnySetterMethod();
if (anySetter != null) {
/* Also, let's be somewhat strict on how field name is to be
* passed; String, Object make sense, others not
* so much.
*/
/* !!! 18-May-2009, tatu: how about enums? Can add support if
* requested; easy enough for devs to add support within
* method.
*/
Class<?> type = anySetter.getRawParameterType(0);
if (type != String.class && type != Object.class) {
throw new IllegalArgumentException("Invalid 'any-setter' annotation on method "+anySetter.getName()+"(): first argument not of type String or Object, but "+type.getName());
}
}
return anySetter;
}
@Override
public Map<Object, AnnotatedMember> findInjectables() {
if (_propCollector != null) {
return _propCollector.getInjectables();
}
return Collections.emptyMap();
}
@Override
public List<AnnotatedConstructor> getConstructors() {
return _classInfo.getConstructors();
}
@Override
public Object instantiateBean(boolean fixAccess)
{
AnnotatedConstructor ac = _classInfo.getDefaultConstructor();
if (ac == null) {
return null;
}
if (fixAccess) {
ac.fixAccess();
}
try {
return ac.getAnnotated().newInstance();
} catch (Exception e) {
Throwable t = e;
while (t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error) throw (Error) t;
if (t instanceof RuntimeException) throw (RuntimeException) t;
throw new IllegalArgumentException("Failed to instantiate bean of type "+_classInfo.getAnnotated().getName()+": ("+t.getClass().getName()+") "+t.getMessage(), t);
}
}
/*
/**********************************************************
/* Simple accessors, extended
/**********************************************************
*/
@Override
public AnnotatedMethod findMethod(String name, Class<?>[] paramTypes) {
return _classInfo.findMethod(name, paramTypes);
}
/*
/**********************************************************
/* General per-class annotation introspection
/**********************************************************
*/
@Override
public JsonFormat.Value findExpectedFormat(JsonFormat.Value defValue)
{
if (_annotationIntrospector != null) {
JsonFormat.Value v = _annotationIntrospector.findFormat(_classInfo);
if (v != null) {
return v;
}
}
return defValue;
}
/*
/**********************************************************
/* Introspection for serialization
/**********************************************************
*/
@Override
public Converter<Object,Object> findSerializationConverter()
{
if (_annotationInt
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.util.List;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
/**
* This intermediate base class is used for all leaf nodes, that is,
* all non-container (array or object) nodes, except for the
* "missing node".
*/
public abstract class ValueNode
extends BaseJsonNode
{
protected ValueNode() { }
@Override
protected JsonNode _at(JsonPointer ptr) {
// will only allow direct matches, but no traversal through
// (base class checks for direct match)
return MissingNode.getInstance();
}
/**
* All current value nodes are immutable, so we can just return
* them as is.
*/
@SuppressWarnings("unchecked")
@Override
public <T extends JsonNode> T deepCopy() { return (T) this; }
@Override public abstract JsonToken asToken();
@Override
public void serializeWithType(JsonGenerator jg, SerializerProvider provider,
TypeSerializer typeSer)
throws IOException, JsonProcessingException
{
typeSer.writeTypePrefixForScalar(this, jg);
serialize(jg, provider);
typeSer.writeTypeSuffixForScalar(this, jg);
}
/*
/**********************************************************************
/* Base impls for standard methods
/**********************************************************************
*/
@Override
public String toString() { return asText(); }
/*
**********************************************************************
* Navigation methods
**********************************************************************
*/
@Override
public final JsonNode get(int index) { return null; }
@Override
public final JsonNode path(int index) { return MissingNode.getInstance(); }
@Override
public final boolean has(int index) { return false; }
@Override
public final boolean hasNonNull(int index) { return false; }
@Override
public final JsonNode get(String fieldName) { return null; }
@Override
public final JsonNode path(String fieldName) { return MissingNode.getInstance(); }
@Override
public final boolean has(String fieldName) { return false; }
@Override
public final boolean hasNonNull(String fieldName) { return false; }
/*
**********************************************************************
* Find methods: all "leaf" nodes return the same for these
**********************************************************************
*/
@Override
public final JsonNode findValue(String fieldName) {
return null;
}
// note: co-variant return type
@Override
public final ObjectNode findParent(String fieldName) {
return null;
}
@Override
public final List<JsonNode> findValues(String fieldName, List<JsonNode> foundSoFar) {
return foundSoFar;
}
@Override
public final List<String> findValuesAsText(String fieldName, List<String> foundSoFar) {
return foundSoFar;
}
@Override
public final List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar) {
return foundSoFar;
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>Matcher == null) || _viewMatcher.isVisibleForView(activeView);
}
public boolean hasViews() { return _viewMatcher != null; }
/**
* Method for accessing unique index of this property; indexes are
* assigned once all properties of a {@link BeanDeserializer} have
* been collected.
*
* @return Index of this property
*/
public int getPropertyIndex() { return _propertyIndex; }
/**
* Method for accessing index of the creator property: for other
* types of properties will simply return -1.
*
* @since 2.1
*/
public int getCreatorIndex() { return -1; }
/**
* Accessor for id of injectable value, if this bean property supports
* value injection.
*/
public Object getInjectableValueId() { return null; }
/*
/**********************************************************
/* Public API
/**********************************************************
*/
/**
* Method called to deserialize appropriate value, given parser (and
* context), and set it using appropriate mechanism.
* Pre-condition is that passed parser must point to the first token
* that should be consumed to produce the value (the only value for
* scalars, multiple for Objects and Arrays).
*/
public abstract void deserializeAndSet(JsonParser p,
DeserializationContext ctxt, Object instance) throws IOException;
/**
* Alternative to {@link #deserializeAndSet} that returns
* either return value of setter method called (if one is),
* or null to indicate that no return value is available.
* Mostly used to support Builder style deserialization.
*
* @since 2.0
*/
public abstract Object deserializeSetAndReturn(JsonParser p,
DeserializationContext ctxt, Object instance) throws IOException;
/**
* Method called to assign given value to this property, on
* specified Object.
*<p>
* Note: this is an optional operation, not supported by all
* implementations, creator-backed properties for example do not
* support this method.
*/
public abstract void set(Object instance, Object value) throws IOException;
/**
* Method called to assign given value to this property, on
* specified Object, and return whatever delegating accessor
* returned (if anything)
*<p>
* Note: this is an optional operation, not supported by all
* implementations, creator-backed properties for example do not
* support this method.
*/
public abstract Object setAndReturn(Object instance, Object value) throws IOException;
/**
* This method is needed by some specialized bean deserializers,
* and also called by some {@link #deserializeAndSet} implementations.
*<p>
* Pre-condition is that passed parser must point to the first token
* that should be consumed to produce the value (the only value for
* scalars, multiple for Objects and Arrays).
*<p>
* Note that this method is final for performance reasons: to override
* functionality you must override other methods that call this method;
* this method should also not be called directly unless you really know
* what you are doing (and probably not even then).
*/
public final Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_NULL) {
return _valueDeserializer.getNullValue(ctxt);
}
if (_valueTypeDeserializer != null) {
return _valueDeserializer.deserializeWithType(p, ctxt, _valueTypeDeserializer
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> isCachable() {
// Important: do NOT cache if polymorphic values
return (_valueDeserializer == null)
&& (_keyDeserializer == null)
&& (_valueTypeDeserializer == null);
}
/*
/**********************************************************
/* ContainerDeserializerBase API
/**********************************************************
*/
@Override
public JavaType getContentType() {
return _mapType.getContentType();
}
@Override
public JsonDeserializer<Object> getContentDeserializer() {
return _valueDeserializer;
}
/*
/**********************************************************
/* Actual deserialization
/**********************************************************
*/
@Override
public EnumMap<?,?> deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
// Ok: must point to START_OBJECT
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
return _deserializeFromEmpty(jp, ctxt);
}
EnumMap result = constructMap();
final JsonDeserializer<Object> valueDes = _valueDeserializer;
final TypeDeserializer typeDeser = _valueTypeDeserializer;
while ((jp.nextToken()) == JsonToken.FIELD_NAME) {
String keyName = jp.getCurrentName(); // just for error message
// but we need to let key deserializer handle it separately, nonetheless
Enum<?> key = (Enum<?>) _keyDeserializer.deserializeKey(keyName, ctxt);
if (key == null) {
if (!ctxt.isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
throw ctxt.weirdStringException(keyName, _enumClass, "value not one of declared Enum instance names for "
+_mapType.getKeyType());
}
/* 24-Mar-2012, tatu: Null won't work as a key anyway, so let's
* just skip the entry then. But we must skip the value as well, if so.
*/
jp.nextToken();
jp.skipChildren();
continue;
}
// And then the value...
JsonToken t = jp.nextToken();
/* note: MUST check for nulls separately: deserializers will
* not handle them (and maybe fail or return bogus data)
*/
Object value;
try {
if (t == JsonToken.VALUE_NULL) {
value = valueDes.getNullValue(ctxt);
} else if (typeDeser == null) {
value = valueDes.deserialize(jp, ctxt);
} else {
value = valueDes.deserializeWithType(jp, ctxt, typeDeser);
}
} catch (Exception e) {
wrapAndThrow(e, result, keyName);
return null;
}
result.put(key, value);
}
return result;
}
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt, TypeDeserializer typeDeserializer)
throws IOException, JsonProcessingException
{
// In future could check current token... for now this should be enough:
return typeDeserializer.deserializeTypedFromObject(jp, ctxt);
}
protected EnumMap<?,?> constructMap() {
return new EnumMap(_enumClass);
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> throws ClassNotFoundException
{
// [JACKSON-597]: support primitive types (and void)
if (className.indexOf('.') < 0) {
if ("int".equals(className)) return Integer.TYPE;
if ("long".equals(className)) return Long.TYPE;
if ("float".equals(className)) return Float.TYPE;
if ("double".equals(className)) return Double.TYPE;
if ("boolean".equals(className)) return Boolean.TYPE;
if ("byte".equals(className)) return Byte.TYPE;
if ("char".equals(className)) return Character.TYPE;
if ("short".equals(className)) return Short.TYPE;
if ("void".equals(className)) return Void.TYPE;
}
// Two-phase lookup: first using context ClassLoader; then default
Throwable prob = null;
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader != null) {
try {
return Class.forName(className, true, loader);
} catch (Exception e) {
prob = getRootCause(e);
}
}
try {
return Class.forName(className);
} catch (Exception e) {
if (prob == null) {
prob = getRootCause(e);
}
}
if (prob instanceof RuntimeException) {
throw (RuntimeException) prob;
}
throw new ClassNotFoundException(prob.getMessage(), prob);
}
/*
/**********************************************************
/* Method type detection methods
/**********************************************************
*/
/**
* @deprecated Since 2.6 not used; may be removed before 3.x
*/
@Deprecated // since 2.6
public static boolean hasGetterSignature(Method m)
{
// First: static methods can't be getters
if (Modifier.isStatic(m.getModifiers())) {
return false;
}
// Must take no args
Class<?>[] pts = m.getParameterTypes();
if (pts != null && pts.length != 0) {
return false;
}
// Can't be a void method
if (Void.TYPE == m.getReturnType()) {
return false;
}
// Otherwise looks ok:
return true;
}
/*
/**********************************************************
/* Exception handling
/**********************************************************
*/
/**
* Method that can be used to find the "root cause", innermost
* of chained (wrapped) exceptions.
*/
public static Throwable getRootCause(Throwable t)
{
while (t.getCause() != null) {
t = t.getCause();
}
return t;
}
/**
* Method that will unwrap root causes of given Throwable, and throw
* the innermost {@link Exception} or {@link Error} as is.
* This is useful in cases where mandatory wrapping is added, which
* is often done by Reflection API.
*/
public static void throwRootCause(Throwable t) throws Exception
{
t = getRootCause(t);
if (t instanceof Exception) {
throw (Exception) t;
}
throw (Error) t;
}
/**
* Method that will wrap 't' as an {@link IllegalArgumentException} if it
* is a checked exception; otherwise (runtime exception or error) throw as is
*/
public static void throwAsIAE(Throwable t)
{
throwAsIAE(t, t.getMessage());
}
/**
* Method that will wrap 't' as an {@link IllegalArgumentException} (and with
* specified
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> message) if it
* is a checked exception; otherwise (runtime exception or error) throw as is
*/
public static void throwAsIAE(Throwable t, String msg)
{
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
if (t instanceof Error) {
throw (Error) t;
}
throw new IllegalArgumentException(msg, t);
}
/**
* Method that will locate the innermost exception for given Throwable;
* and then wrap it as an {@link IllegalArgumentException} if it
* is a checked exception; otherwise (runtime exception or error) throw as is
*/
public static void unwrapAndThrowAsIAE(Throwable t)
{
throwAsIAE(getRootCause(t));
}
/**
* Method that will locate the innermost exception for given Throwable;
* and then wrap it as an {@link IllegalArgumentException} if it
* is a checked exception; otherwise (runtime exception or error) throw as is
*/
public static void unwrapAndThrowAsIAE(Throwable t, String msg)
{
throwAsIAE(getRootCause(t), msg);
}
/*
/**********************************************************
/* Instantiation
/**********************************************************
*/
/**
* Method that can be called to try to create an instantiate of
* specified type. Instantiation is done using default no-argument
* constructor.
*
* @param canFixAccess Whether it is possible to try to change access
* rights of the default constructor (in case it is not publicly
* accessible) or not.
*
* @throws IllegalArgumentException If instantiation fails for any reason;
* except for cases where constructor throws an unchecked exception
* (which will be passed as is)
*/
public static <T> T createInstance(Class<T> cls, boolean canFixAccess)
throws IllegalArgumentException
{
Constructor<T> ctor = findConstructor(cls, canFixAccess);
if (ctor == null) {
throw new IllegalArgumentException("Class "+cls.getName()+" has no default (no arg) constructor");
}
try {
return ctor.newInstance();
} catch (Exception e) {
ClassUtil.unwrapAndThrowAsIAE(e, "Failed to instantiate class "+cls.getName()+", problem: "+e.getMessage());
return null;
}
}
public static <T> Constructor<T> findConstructor(Class<T> cls, boolean canFixAccess)
throws IllegalArgumentException
{
try {
Constructor<T> ctor = cls.getDeclaredConstructor();
if (canFixAccess) {
checkAndFixAccess(ctor);
} else {
// Has to be public...
if (!Modifier.isPublic(ctor.getModifiers())) {
throw new IllegalArgumentException("Default constructor for "+cls.getName()+" is not accessible (non-public?): not allowed to try modify access via Reflection: can not instantiate type");
}
}
return ctor;
} catch (NoSuchMethodException e) {
;
} catch (Exception e) {
ClassUtil.unwrapAndThrowAsIAE(e, "Failed to find default constructor of class "+cls.getName()+", problem: "+e.getMessage());
}
return null;
}
/*
/**********************************************************
/* Primitive type support
/**********************************************************
*/
/**
* Helper method used to get default value for wrappers used for primitive types
* (0 for Integer etc)
*/
public static Object defaultValue(Class<?> cls)
{
if (cls == Integer.TYPE) {
return Integer
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>
/**********************************************************
/* Helper classes
/**********************************************************
*/
/**
* Inner class used to contain gory details of how we can determine
* details of instances of common JDK types like {@link EnumMap}s.
*/
private static class EnumTypeLocator
{
final static EnumTypeLocator instance = new EnumTypeLocator();
private final Field enumSetTypeField;
private final Field enumMapTypeField;
private EnumTypeLocator() {
//JDK uses following fields to store information about actual Enumeration
// type for EnumSets, EnumMaps...
enumSetTypeField = locateField(EnumSet.class, "elementType", Class.class);
enumMapTypeField = locateField(EnumMap.class, "elementType", Class.class);
}
@SuppressWarnings("unchecked")
public Class<? extends Enum<?>> enumTypeFor(EnumSet<?> set)
{
if (enumSetTypeField != null) {
return (Class<? extends Enum<?>>) get(set, enumSetTypeField);
}
throw new IllegalStateException("Can not figure out type for EnumSet (odd JDK platform?)");
}
@SuppressWarnings("unchecked")
public Class<? extends Enum<?>> enumTypeFor(EnumMap<?,?> set)
{
if (enumMapTypeField != null) {
return (Class<? extends Enum<?>>) get(set, enumMapTypeField);
}
throw new IllegalStateException("Can not figure out type for EnumMap (odd JDK platform?)");
}
private Object get(Object bean, Field field)
{
try {
return field.get(bean);
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
private static Field locateField(Class<?> fromClass, String expectedName, Class<?> type)
{
Field found = null;
// First: let's see if we can find exact match:
Field[] fields = fromClass.getDeclaredFields();
for (Field f : fields) {
if (expectedName.equals(f.getName()) && f.getType() == type) {
found = f;
break;
}
}
// And if not, if there is just one field with the type, that field
if (found == null) {
for (Field f : fields) {
if (f.getType() == type) {
// If more than one, can't choose
if (found != null) return null;
found = f;
}
}
}
if (found != null) { // it's non-public, need to force accessible
try {
found.setAccessible(true);
} catch (Throwable t) { }
}
return found;
}
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>Type.getType(), name);
}
}
if (namedType.hasName()) {
byName.put(namedType.getName(), namedType);
}
// only check subtypes if this type hadn't yet been handled
if (typesHandled.add(namedType.getType())) {
Collection<NamedType> st = ai.findSubtypes(annotatedType);
if (st != null && !st.isEmpty()) {
for (NamedType subtype : st) {
AnnotatedClass subtypeClass = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), ai, config);
_collectAndResolveByTypeId(subtypeClass, subtype, config, typesHandled, byName);
}
}
}
}
/**
* Helper method used for merging explicitly named types and handled classes
* without explicit names.
*/
protected Collection<NamedType> _combineNamedAndUnnamed(Set<Class<?>> typesHandled,
Map<String,NamedType> byName)
{
ArrayList<NamedType> result = new ArrayList<NamedType>(byName.values());
// Ok, so... we will figure out which classes have no explicitly assigned name,
// by removing Classes from Set. And for remaining classes, add an anonymous
// marker
for (NamedType t : byName.values()) {
typesHandled.remove(t.getType());
}
for (Class<?> cls : typesHandled) {
result.add(new NamedType(cls));
}
return result;
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>._last);
}
}
private Gender _gender;
private Name _name;
private boolean _isVerified;
private byte[] _userImage;
public FiveMinuteUser() { }
public FiveMinuteUser(String first, String last, boolean verified, Gender g, byte[] data)
{
_name = new Name(first, last);
_isVerified = verified;
_gender = g;
_userImage = data;
}
public Name getName() { return _name; }
public boolean isVerified() { return _isVerified; }
public Gender getGender() { return _gender; }
public byte[] getUserImage() { return _userImage; }
public void setName(Name n) { _name = n; }
public void setVerified(boolean b) { _isVerified = b; }
public void setGender(Gender g) { _gender = g; }
public void setUserImage(byte[] b) { _userImage = b; }
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
FiveMinuteUser other = (FiveMinuteUser) o;
if (_isVerified != other._isVerified) return false;
if (_gender != other._gender) return false;
if (!_name.equals(other._name)) return false;
byte[] otherImage = other._userImage;
if (otherImage.length != _userImage.length) return false;
for (int i = 0, len = _userImage.length; i < len; ++i) {
if (_userImage[i] != otherImage[i]) {
return false;
}
}
return true;
}
}
/*
/**********************************************************
/* High-level helpers
/**********************************************************
*/
protected void verifyJsonSpecSampleDoc(JsonParser jp, boolean verifyContents)
throws IOException
{
verifyJsonSpecSampleDoc(jp, verifyContents, true);
}
protected void verifyJsonSpecSampleDoc(JsonParser jp, boolean verifyContents,
boolean requireNumbers)
throws IOException
{
if (!jp.hasCurrentToken()) {
jp.nextToken();
}
assertToken(JsonToken.START_OBJECT, jp.getCurrentToken()); // main object
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Image'
if (verifyContents) {
verifyFieldName(jp, "Image");
}
assertToken(JsonToken.START_OBJECT, jp.nextToken()); // 'image' object
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Width'
if (verifyContents) {
verifyFieldName(jp, "Width");
}
verifyIntToken(jp.nextToken(), requireNumbers);
if (verifyContents) {
verifyIntValue(jp, SAMPLE_SPEC_VALUE_WIDTH);
}
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Height'
if (verifyContents) {
verifyFieldName(jp, "Height");
}
verifyIntToken(jp.nextToken(), requireNumbers);
if (verifyContents) {
verifyIntValue(jp, SAMPLE_SPEC_VALUE_HEIGHT);
}
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Title'
if (verifyContents) {
verifyFieldName(jp, "Title");
}
assertToken(JsonToken.VALUE_
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>STRING, jp.nextToken());
assertEquals(SAMPLE_SPEC_VALUE_TITLE, getAndVerifyText(jp));
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Thumbnail'
if (verifyContents) {
verifyFieldName(jp, "Thumbnail");
}
assertToken(JsonToken.START_OBJECT, jp.nextToken()); // 'thumbnail' object
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Url'
if (verifyContents) {
verifyFieldName(jp, "Url");
}
assertToken(JsonToken.VALUE_STRING, jp.nextToken());
if (verifyContents) {
assertEquals(SAMPLE_SPEC_VALUE_TN_URL, getAndVerifyText(jp));
}
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Height'
if (verifyContents) {
verifyFieldName(jp, "Height");
}
verifyIntToken(jp.nextToken(), requireNumbers);
if (verifyContents) {
verifyIntValue(jp, SAMPLE_SPEC_VALUE_TN_HEIGHT);
}
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Width'
if (verifyContents) {
verifyFieldName(jp, "Width");
}
// Width value is actually a String in the example
assertToken(JsonToken.VALUE_STRING, jp.nextToken());
if (verifyContents) {
assertEquals(SAMPLE_SPEC_VALUE_TN_WIDTH, getAndVerifyText(jp));
}
assertToken(JsonToken.END_OBJECT, jp.nextToken()); // 'thumbnail' object
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'IDs'
assertToken(JsonToken.START_ARRAY, jp.nextToken()); // 'ids' array
verifyIntToken(jp.nextToken(), requireNumbers); // ids[0]
if (verifyContents) {
verifyIntValue(jp, SAMPLE_SPEC_VALUE_TN_ID1);
}
verifyIntToken(jp.nextToken(), requireNumbers); // ids[1]
if (verifyContents) {
verifyIntValue(jp, SAMPLE_SPEC_VALUE_TN_ID2);
}
verifyIntToken(jp.nextToken(), requireNumbers); // ids[2]
if (verifyContents) {
verifyIntValue(jp, SAMPLE_SPEC_VALUE_TN_ID3);
}
verifyIntToken(jp.nextToken(), requireNumbers); // ids[3]
if (verifyContents) {
verifyIntValue(jp, SAMPLE_SPEC_VALUE_TN_ID4);
}
assertToken(JsonToken.END_ARRAY, jp.nextToken()); // 'ids' array
assertToken(JsonToken.END_OBJECT, jp.nextToken()); // 'image' object
assertToken(JsonToken.END_OBJECT, jp.nextToken()); // main object
}
private void verifyIntToken(JsonToken t, boolean requireNumbers)
{
if (t == JsonToken.VALUE_NUMBER_INT) {
return;
}
if (requireNumbers) { // to get error
assertToken(JsonToken.VALUE_NUMBER_INT, t);
}
// if not number, must be String
if (t != JsonToken.VALUE_STRING) {
fail("Expected INT or STRING value, got "+t);
}
}
protected void verifyFieldName(JsonParser jp, String expName)
throws IOException
{
assertEquals(expName, jp.getText());
assertEquals(expName,
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> jp.getCurrentName());
}
protected void verifyIntValue(JsonParser jp, long expValue)
throws IOException
{
// First, via textual
assertEquals(String.valueOf(expValue), jp.getText());
}
/**
* Method that checks whether Unit tests appear to run from Ant build
* scripts.
*
* @since 1.6
*/
protected static boolean runsFromAnt() {
return "true".equals(System.getProperty("FROM_ANT"));
}
/*
/**********************************************************
/* Parser/generator construction
/**********************************************************
*/
protected JsonParser createParserUsingReader(String input)
throws IOException, JsonParseException
{
return createParserUsingReader(new JsonFactory(), input);
}
protected JsonParser createParserUsingReader(JsonFactory f, String input)
throws IOException, JsonParseException
{
return f.createParser(new StringReader(input));
}
protected JsonParser createParserUsingStream(String input, String encoding)
throws IOException, JsonParseException
{
return createParserUsingStream(new JsonFactory(), input, encoding);
}
protected JsonParser createParserUsingStream(JsonFactory f,
String input, String encoding)
throws IOException, JsonParseException
{
/* 23-Apr-2008, tatus: UTF-32 is not supported by JDK, have to
* use our own codec too (which is not optimal since there's
* a chance both encoder and decoder might have bugs, but ones
* that cancel each other out or such)
*/
byte[] data;
if (encoding.equalsIgnoreCase("UTF-32")) {
data = encodeInUTF32BE(input);
} else {
data = input.getBytes(encoding);
}
InputStream is = new ByteArrayInputStream(data);
return f.createParser(is);
}
/*
/**********************************************************
/* Additional assertion methods
/**********************************************************
*/
protected void assertToken(JsonToken expToken, JsonToken actToken)
{
if (actToken != expToken) {
fail("Expected token "+expToken+", current token "+actToken);
}
}
protected void assertToken(JsonToken expToken, JsonParser jp)
{
assertToken(expToken, jp.getCurrentToken());
}
protected void assertType(Object ob, Class<?> expType)
{
if (ob == null) {
fail("Expected an object of type "+expType.getName()+", got null");
}
Class<?> cls = ob.getClass();
if (!expType.isAssignableFrom(cls)) {
fail("Expected type "+expType.getName()+", got "+cls.getName());
}
}
protected void assertValidLocation(JsonLocation location) {
assertNotNull("Should have non-null location", location);
assertTrue("Should have positive line number", location.getLineNr() > 0);
}
protected void verifyException(Throwable e, String... matches)
{
String msg = e.getMessage();
String lmsg = (msg == null) ? "" : msg.toLowerCase();
for (String match : matches) {
String lmatch = match.toLowerCase();
if (lmsg.indexOf(lmatch) >= 0) {
return;
}
}
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
}
/**
* Method that gets textual contents of the current token using
* available methods, and
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> */
/**
* General version used when handling needs more advanced
* features.
*/
public abstract Object deserializeFromObject(JsonParser p, DeserializationContext ctxt)
throws IOException;
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer)
throws IOException
{
// 16-Feb-2012, tatu: ObjectId may be used as well... need to check that first
if (_objectIdReader != null) {
// 05-Aug-2013, tatu: May use native Object Id
if (p.canReadObjectId()) {
Object id = p.getObjectId();
if (id != null) {
Object ob = typeDeserializer.deserializeTypedFromObject(p, ctxt);
return _handleTypedObjectId(p, ctxt, ob, id);
}
}
// or, Object Ids Jackson explicitly sets
JsonToken t = p.getCurrentToken();
if (t != null) {
// Most commonly, a scalar (int id, uuid String, ...)
if (t.isScalarValue()) {
return deserializeFromObjectId(p, ctxt);
}
// but, with 2.5+, a simple Object-wrapped value also legal:
if (t == JsonToken.START_OBJECT) {
t = p.nextToken();
}
if (t == JsonToken.FIELD_NAME && _objectIdReader.maySerializeAsObject()
&& _objectIdReader.isValidReferencePropertyName(p.getCurrentName(), p)) {
return deserializeFromObjectId(p, ctxt);
}
}
}
// In future could check current token... for now this should be enough:
return typeDeserializer.deserializeTypedFromObject(p, ctxt);
}
/**
* Offlined method called to handle "native" Object Id that has been read
* and known to be associated with given deserialized POJO.
*
* @since 2.3
*/
protected Object _handleTypedObjectId(JsonParser jp, DeserializationContext ctxt,
Object pojo, Object rawId)
throws IOException
{
/* 07-Aug-2013, tatu: One more challenge: type of id may not be type
* of property we are expecting later on; specifically, numeric ids
* vs Strings.
*/
JsonDeserializer<Object> idDeser = _objectIdReader.getDeserializer();
final Object id;
// Ok, this is bit ridiculous; let's see if conversion is needed:
if (idDeser.handledType() == rawId.getClass()) {
// nope: already same type
id = rawId;
} else {
id = _convertObjectId(jp, ctxt, rawId, idDeser);
}
ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver);
roid.bindItem(pojo);
// also: may need to set a property value as well
SettableBeanProperty idProp = _objectIdReader.idProperty;
if (idProp != null) {
return idProp.setAndReturn(pojo, id);
}
return pojo;
}
/**
* Helper method we need to do necessary conversion from whatever native object id
* type is, into declared type that Jackson internals expect. This may be
* simple cast (for String ids), or something more complicated; in latter
* case we may need to create bogus content buffer to allow
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> use of
* id deserializer.
*
* @since 2.3
*/
@SuppressWarnings("resource") // TokenBuffers don't need close, nor parser thereof
protected Object _convertObjectId(JsonParser p, DeserializationContext ctxt,
Object rawId, JsonDeserializer<Object> idDeser) throws IOException
{
TokenBuffer buf = new TokenBuffer(p, ctxt);
if (rawId instanceof String) {
buf.writeString((String) rawId);
} else if (rawId instanceof Long) {
buf.writeNumber(((Long) rawId).longValue());
} else if (rawId instanceof Integer) {
buf.writeNumber(((Integer) rawId).intValue());
} else {
// should we worry about UUIDs? They should be fine, right?
// 07-Aug-2014, tatu: Maybe, but not necessarily; had issues with
// Smile format; [Smile#19], possibly related.
buf.writeObject(rawId);
}
JsonParser bufParser = buf.asParser();
bufParser.nextToken();
return idDeser.deserialize(bufParser, ctxt);
}
// NOTE: currently only used by standard BeanDeserializer (not Builder-based)
/**
* Alternative deserialization method used when we expect to see Object Id;
* if so, we will need to ensure that the Id is seen before anything
* else, to ensure that it is available for solving references,
* even if JSON itself is not ordered that way. This may require
* buffering in some cases, but usually just a simple lookup to ensure
* that ordering is correct.
*/
protected Object deserializeWithObjectId(JsonParser jp, DeserializationContext ctxt) throws IOException {
return deserializeFromObject(jp, ctxt);
}
/**
* Method called in cases where it looks like we got an Object Id
* to parse and use as a reference.
*/
protected Object deserializeFromObjectId(JsonParser jp, DeserializationContext ctxt) throws IOException
{
Object id = _objectIdReader.readObjectReference(jp, ctxt);
ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver);
// do we have it resolved?
Object pojo = roid.resolve();
if (pojo == null) { // not yet; should wait...
throw new UnresolvedForwardReference("Could not resolve Object Id ["+id+"] (for "
+_beanType+").", jp.getCurrentLocation(), roid);
}
return pojo;
}
protected Object deserializeFromObjectUsingNonDefault(JsonParser jp,
DeserializationContext ctxt) throws IOException
{
if (_delegateDeserializer != null) {
return _valueInstantiator.createUsingDelegate(ctxt,
_delegateDeserializer.deserialize(jp, ctxt));
}
if (_propertyBasedCreator != null) {
return _deserializeUsingPropertyBased(jp, ctxt);
}
// should only occur for abstract types...
if (_beanType.isAbstract()) {
throw JsonMappingException.from(jp, "Can not instantiate abstract type "+_beanType
+" (need to add/enable type information?)");
}
throw JsonMappingException.from(jp, "No suitable constructor found for type "
+_beanType+": can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?)");
}
protected abstract Object _deserializeUsingPropertyBased(final Json
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>, ctxt));
}
throw ctxt.instantiationException(handledType(), "no suitable creator method found to deserialize from JSON floating-point number");
}
/**
* Method called to deserialize POJO value from a JSON boolean value (true, false)
*/
public Object deserializeFromBoolean(JsonParser p, DeserializationContext ctxt) throws IOException
{
if (_delegateDeserializer != null) {
if (!_valueInstantiator.canCreateFromBoolean()) {
Object bean = _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.deserialize(p, ctxt));
if (_injectables != null) {
injectValues(ctxt, bean);
}
return bean;
}
}
boolean value = (p.getCurrentToken() == JsonToken.VALUE_TRUE);
return _valueInstantiator.createFromBoolean(ctxt, value);
}
public Object deserializeFromArray(JsonParser p, DeserializationContext ctxt) throws IOException
{
if (_delegateDeserializer != null) {
try {
Object bean = _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.deserialize(p, ctxt));
if (_injectables != null) {
injectValues(ctxt, bean);
}
return bean;
} catch (Exception e) {
wrapInstantiationProblem(e, ctxt);
}
}
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
JsonToken t = p.nextToken();
if (t == JsonToken.END_ARRAY && ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT)) {
return null;
}
final Object value = deserialize(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single '" + _valueClass.getName() + "' value but there was more than a single value in the array");
}
return value;
}
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT)) {
JsonToken t = p.nextToken();
if (t == JsonToken.END_ARRAY) {
return null;
}
throw ctxt.mappingException(handledType(), JsonToken.START_ARRAY);
}
throw ctxt.mappingException(handledType());
}
public Object deserializeFromEmbedded(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// First things first: id Object Id is used, most likely that's it; specifically,
// true for UUIDs when written as binary (with Smile, other binary formats)
if (_objectIdReader != null) {
return deserializeFromObjectId(jp, ctxt);
}
// TODO: maybe add support for ValueInstantiator, embedded?
return jp.getEmbeddedObject();
}
/*
/**********************************************************
/* Overridable helper methods
/**********************************************************
*/
protected void injectValues(DeserializationContext ctxt, Object bean)
throws IOException, JsonProcessingException
{
for (ValueInjector injector : _injectables) {
injector.inject(ctxt, bean);
}
}
/**
* Method called to handle set of one or more unknown properties,
* stored in their entirety in given {@link TokenBuffer}
* (as field entries, name and value).
*/
@SuppressWarnings("resource")
protected Object handleUnknownProperties(DeserializationContext ctxt,
Object bean, TokenBuffer unknownTokens)
throws IOException
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>, JsonProcessingException
{
// First: add closing END_OBJECT as marker
unknownTokens.writeEndObject();
// note: buffer does NOT have starting START_OBJECT
JsonParser bufferParser = unknownTokens.asParser();
while (bufferParser.nextToken() != JsonToken.END_OBJECT) {
String propName = bufferParser.getCurrentName();
// Unknown: let's call handler method
bufferParser.nextToken();
handleUnknownProperty(bufferParser, ctxt, bean, propName);
}
return bean;
}
/**
* Helper method called for an unknown property, when using "vanilla"
* processing.
*/
protected void handleUnknownVanilla(JsonParser jp, DeserializationContext ctxt,
Object bean, String propName)
throws IOException, JsonProcessingException
{
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(jp, ctxt, bean, propName);
} else if (_anySetter != null) {
try {
// should we consider return type of any setter?
_anySetter.deserializeAndSet(jp, ctxt, bean, propName);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
} else {
// Unknown: let's call handler method
handleUnknownProperty(jp, ctxt, bean, propName);
}
}
/**
* Method called when a JSON property is encountered that has not matching
* setter, any-setter or field, and thus can not be assigned.
*/
@Override
protected void handleUnknownProperty(JsonParser jp, DeserializationContext ctxt,
Object beanOrClass, String propName)
throws IOException, JsonProcessingException
{
if (_ignoreAllUnknown) {
jp.skipChildren();
return;
}
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(jp, ctxt, beanOrClass, propName);
}
// Otherwise use default handling (call handler(s); if not
// handled, throw exception or skip depending on settings)
super.handleUnknownProperty(jp, ctxt, beanOrClass, propName);
}
/**
* Method called when an explicitly ignored property (one specified with a
* name to match, either by property annotation or class annotation) is encountered.
*
* @since 2.3
*/
protected void handleIgnoredProperty(JsonParser jp, DeserializationContext ctxt,
Object beanOrClass, String propName)
throws IOException, JsonProcessingException
{
if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES)) {
throw IgnoredPropertyException.from(jp, beanOrClass, propName, getKnownPropertyNames());
}
jp.skipChildren();
}
/**
* Method called in cases where we may have polymorphic deserialization
* case: that is, type of Creator-constructed bean is not the type
* of deserializer itself. It should be a sub-class or implementation
* class; either way, we may have more specific deserializer to use
* for handling it.
*
* @param jp (optional) If not null, parser that has more properties to handle
* (in addition to buffered properties); if null, all properties are passed
* in buffer
*/
@SuppressWarnings("resource")
protected Object handlePolymorphic(JsonParser jp, DeserializationContext ctxt,
Object bean, TokenBuffer unknownTokens
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>)
throws IOException, JsonProcessingException
{
// First things first: maybe there is a more specific deserializer available?
JsonDeserializer<Object> subDeser = _findSubclassDeserializer(ctxt, bean, unknownTokens);
if (subDeser != null) {
if (unknownTokens != null) {
// need to add END_OBJECT marker first
unknownTokens.writeEndObject();
JsonParser p2 = unknownTokens.asParser();
p2.nextToken(); // to get to first data field
bean = subDeser.deserialize(p2, ctxt, bean);
}
// Original parser may also have some leftovers
if (jp != null) {
bean = subDeser.deserialize(jp, ctxt, bean);
}
return bean;
}
// nope; need to use this deserializer. Unknowns we've seen so far?
if (unknownTokens != null) {
bean = handleUnknownProperties(ctxt, bean, unknownTokens);
}
// and/or things left to process via main parser?
if (jp != null) {
bean = deserialize(jp, ctxt, bean);
}
return bean;
}
/**
* Helper method called to (try to) locate deserializer for given sub-type of
* type that this deserializer handles.
*/
protected JsonDeserializer<Object> _findSubclassDeserializer(DeserializationContext ctxt,
Object bean, TokenBuffer unknownTokens)
throws IOException, JsonProcessingException
{
JsonDeserializer<Object> subDeser;
// First: maybe we have already created sub-type deserializer?
synchronized (this) {
subDeser = (_subDeserializers == null) ? null : _subDeserializers.get(new ClassKey(bean.getClass()));
}
if (subDeser != null) {
return subDeser;
}
// If not, maybe we can locate one. First, need provider
JavaType type = ctxt.constructType(bean.getClass());
/* 30-Jan-2012, tatu: Ideally we would be passing referring
* property; which in theory we could keep track of via
* ResolvableDeserializer (if we absolutely must...).
* But for now, let's not bother.
*/
// subDeser = ctxt.findValueDeserializer(type, _property);
subDeser = ctxt.findRootValueDeserializer(type);
// Also, need to cache it
if (subDeser != null) {
synchronized (this) {
if (_subDeserializers == null) {
_subDeserializers = new HashMap<ClassKey,JsonDeserializer<Object>>();;
}
_subDeserializers.put(new ClassKey(bean.getClass()), subDeser);
}
}
return subDeser;
}
/*
/**********************************************************
/* Helper methods for error reporting
/**********************************************************
*/
/**
* Method that will modify caught exception (passed in as argument)
* as necessary to include reference information, and to ensure it
* is a subtype of {@link IOException}, or an unchecked exception.
*<p>
* Rules for wrapping and unwrapping are bit complicated; essentially:
*<ul>
* <li>Errors are to be passed as is (if uncovered via unwrapping)
* <li>"Plain" IOExceptions (ones that are not of type
* {@link JsonMappingException} are to be passed as is
*</ul>
*/
public void wrapAnd
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>Throw(Throwable t, Object bean, String fieldName, DeserializationContext ctxt)
throws IOException
{
// [JACKSON-55] Need to add reference information
throw JsonMappingException.wrapWithPath(throwOrReturnThrowable(t, ctxt), bean, fieldName);
}
@Deprecated // since 2.4, not used by core Jackson; only relevant for arrays/Collections
public void wrapAndThrow(Throwable t, Object bean, int index, DeserializationContext ctxt) throws IOException {
// [JACKSON-55] Need to add reference information
throw JsonMappingException.wrapWithPath(throwOrReturnThrowable(t, ctxt), bean, index);
}
private Throwable throwOrReturnThrowable(Throwable t, DeserializationContext ctxt)
throws IOException
{
/* 05-Mar-2009, tatu: But one nasty edge is when we get
* StackOverflow: usually due to infinite loop. But that
* often gets hidden within an InvocationTargetException...
*/
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors to be passed as is
if (t instanceof Error) {
throw (Error) t;
}
boolean wrap = (ctxt == null) || ctxt.isEnabled(DeserializationFeature.WRAP_EXCEPTIONS);
// Ditto for IOExceptions; except we may want to wrap JSON exceptions
if (t instanceof IOException) {
if (!wrap || !(t instanceof JsonProcessingException)) {
throw (IOException) t;
}
} else if (!wrap) { // [JACKSON-407] -- allow disabling wrapping for unchecked exceptions
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
}
return t;
}
protected void wrapInstantiationProblem(Throwable t, DeserializationContext ctxt)
throws IOException
{
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors and "plain" IOExceptions to be passed as is
if (t instanceof Error) {
throw (Error) t;
}
boolean wrap = (ctxt == null) || ctxt.isEnabled(DeserializationFeature.WRAP_EXCEPTIONS);
if (t instanceof IOException) {
// Since we have no more information to add, let's not actually wrap..
throw (IOException) t;
} else if (!wrap) { // [JACKSON-407] -- allow disabling wrapping for unchecked exceptions
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
}
throw ctxt.instantiationException(_beanType.getRawClass(), t);
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* This concrete value class is used to contain boolean (true / false)
* values. Only two instances are ever created, to minimize memory
* usage.
*/
public class BooleanNode
extends ValueNode
{
// // Just need two instances...
public final static BooleanNode TRUE = new BooleanNode(true);
public final static BooleanNode FALSE = new BooleanNode(false);
private final boolean _value;
private BooleanNode(boolean v) { _value = v; }
public static BooleanNode getTrue() { return TRUE; }
public static BooleanNode getFalse() { return FALSE; }
public static BooleanNode valueOf(boolean b) { return b ? TRUE : FALSE; }
@Override
public JsonNodeType getNodeType() {
return JsonNodeType.BOOLEAN;
}
@Override public JsonToken asToken() {
return _value ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE;
}
@Override
public boolean booleanValue() {
return _value;
}
@Override
public String asText() {
return _value ? "true" : "false";
}
@Override
public boolean asBoolean() {
return _value;
}
@Override
public boolean asBoolean(boolean defaultValue) {
return _value;
}
@Override
public int asInt(int defaultValue) {
return _value ? 1 : 0;
}
@Override
public long asLong(long defaultValue) {
return _value ? 1L : 0L;
}
@Override
public double asDouble(double defaultValue) {
return _value ? 1.0 : 0.0;
}
@Override
public final void serialize(JsonGenerator g, SerializerProvider provider) throws IOException {
g.writeBoolean(_value);
}
@Override
public int hashCode() {
return _value ? 3 : 1;
}
@Override
public boolean equals(Object o)
{
/* 11-Mar-2013, tatu: Apparently ClassLoaders can manage to load
* different instances, rendering identity comparisons broken.
* So let's use value instead.
*/
if (o == this) return true;
if (o == null) return false;
if (!(o instanceof BooleanNode)) {
return false;
}
return (_value == ((BooleanNode) o)._value);
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>
/**********************************************************
*/
@Override
public JavaType getContentType() {
return _mapType.getContentType();
}
@Override
public JsonDeserializer<Object> getContentDeserializer() {
return _valueDeserializer;
}
/*
/**********************************************************
/* JsonDeserializer API
/**********************************************************
*/
/**
* Turns out that these are expensive enough to create so that caching
* does make sense.
*<p>
* IMPORTANT: but, note, that instances CAN NOT BE CACHED if there is
* a value type deserializer; this caused an issue with 2.4.4 of
* JAXB Annotations (failing a test).
* It is also possible that some other settings could make deserializers
* un-cacheable; but on the other hand, caching can make a big positive
* difference with performance... so it's a hard choice.
*
* @since 2.4.4
*/
@Override
public boolean isCachable() {
/* As per [databind#735], existence of value or key deserializer (only passed
* if annotated to use non-standard one) should also prevent caching.
*/
return (_valueDeserializer == null)
&& (_keyDeserializer == null)
&& (_valueTypeDeserializer == null)
&& (_ignorableProperties == null);
}
@Override
@SuppressWarnings("unchecked")
public Map<Object,Object> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
if (_propertyBasedCreator != null) {
return _deserializeUsingCreator(p, ctxt);
}
if (_delegateDeserializer != null) {
return (Map<Object,Object>) _valueInstantiator.createUsingDelegate(ctxt,
_delegateDeserializer.deserialize(p, ctxt));
}
if (!_hasDefaultCreator) {
throw ctxt.instantiationException(getMapClass(), "No default constructor found");
}
// Ok: must point to START_OBJECT, FIELD_NAME or END_OBJECT
JsonToken t = p.getCurrentToken();
if (t != JsonToken.START_OBJECT && t != JsonToken.FIELD_NAME && t != JsonToken.END_OBJECT) {
// [JACKSON-620] (empty) String may be ok however:
if (t == JsonToken.VALUE_STRING) {
return (Map<Object,Object>) _valueInstantiator.createFromString(ctxt, p.getText());
}
// slightly redundant (since String was passed above), but
return _deserializeFromEmpty(p, ctxt);
}
final Map<Object,Object> result = (Map<Object,Object>) _valueInstantiator.createUsingDefault(ctxt);
if (_standardStringKey) {
_readAndBindStringMap(p, ctxt, result);
return result;
}
_readAndBind(p, ctxt, result);
return result;
}
@Override
public Map<Object,Object> deserialize(JsonParser p, DeserializationContext ctxt,
Map<Object,Object> result)
throws IOException
{
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(result);
// Ok: must point to START_OBJECT or FIELD_NAME
JsonToken t = p.getCurrentToken();
if (t != JsonToken.START_OBJECT && t != JsonToken.FIELD_NAME) {
throw ctxt.mappingException(getMapClass());
}
if (_standardStringKey) {
_
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>readAndBindStringMap(p, ctxt, result);
return result;
}
_readAndBind(p, ctxt, result);
return result;
}
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt,
TypeDeserializer typeDeserializer)
throws IOException, JsonProcessingException
{
// In future could check current token... for now this should be enough:
return typeDeserializer.deserializeTypedFromObject(jp, ctxt);
}
/*
/**********************************************************
/* Other public accessors
/**********************************************************
*/
@SuppressWarnings("unchecked")
public final Class<?> getMapClass() { return (Class<Map<Object,Object>>) _mapType.getRawClass(); }
@Override public JavaType getValueType() { return _mapType; }
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected final void _readAndBind(JsonParser p, DeserializationContext ctxt,
Map<Object,Object> result) throws IOException
{
final KeyDeserializer keyDes = _keyDeserializer;
final JsonDeserializer<Object> valueDes = _valueDeserializer;
final TypeDeserializer typeDeser = _valueTypeDeserializer;
MapReferringAccumulator referringAccumulator = null;
boolean useObjectId = valueDes.getObjectIdReader() != null;
if (useObjectId) {
referringAccumulator = new MapReferringAccumulator(_mapType.getContentType().getRawClass(), result);
}
String keyStr;
if (p.isExpectedStartObjectToken()) {
keyStr = p.nextFieldName();
} else {
JsonToken t = p.getCurrentToken();
if (t == JsonToken.END_OBJECT) {
return;
}
if (t != JsonToken.FIELD_NAME) {
throw ctxt.mappingException(_mapType.getRawClass(), p.getCurrentToken());
}
keyStr = p.getCurrentName();
}
for (; keyStr != null; keyStr = p.nextFieldName()) {
Object key = keyDes.deserializeKey(keyStr, ctxt);
// And then the value...
JsonToken t = p.nextToken();
if (_ignorableProperties != null && _ignorableProperties.contains(keyStr)) {
p.skipChildren();
continue;
}
try {
// Note: must handle null explicitly here; value deserializers won't
Object value;
if (t == JsonToken.VALUE_NULL) {
value = valueDes.getNullValue(ctxt);
} else if (typeDeser == null) {
value = valueDes.deserialize(p, ctxt);
} else {
value = valueDes.deserializeWithType(p, ctxt, typeDeser);
}
if (useObjectId) {
referringAccumulator.put(key, value);
} else {
result.put(key, value);
}
} catch (UnresolvedForwardReference reference) {
handleUnresolvedReference(p, referringAccumulator, key, reference);
} catch (Exception e) {
wrapAndThrow(e, result, keyStr);
}
}
}
/**
* Optimized method used when keys can be deserialized as plain old
* {@link java.lang.String}s, and there is no custom deserialized
* specified.
*/
protected final void _readAndBindStringMap(JsonParser p, DeserializationContext ctxt,
Map<Object,Object> result) throws IOException
{
final JsonDeserializer<Object> valueDes = _valueDeserializer;
final TypeDeserializer typeDeser = _valueTypeDeserializer
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>;
MapReferringAccumulator referringAccumulator = null;
boolean useObjectId = (valueDes.getObjectIdReader() != null);
if (useObjectId) {
referringAccumulator = new MapReferringAccumulator(_mapType.getContentType().getRawClass(), result);
}
String key;
if (p.isExpectedStartObjectToken()) {
key = p.nextFieldName();
} else {
JsonToken t = p.getCurrentToken();
if (t == JsonToken.END_OBJECT) {
return;
}
if (t != JsonToken.FIELD_NAME) {
throw ctxt.mappingException(_mapType.getRawClass(), p.getCurrentToken());
}
key = p.getCurrentName();
}
for (; key != null; key = p.nextFieldName()) {
JsonToken t = p.nextToken();
if (_ignorableProperties != null && _ignorableProperties.contains(key)) {
p.skipChildren();
continue;
}
try {
// Note: must handle null explicitly here; value deserializers won't
Object value;
if (t == JsonToken.VALUE_NULL) {
value = valueDes.getNullValue(ctxt);
} else if (typeDeser == null) {
value = valueDes.deserialize(p, ctxt);
} else {
value = valueDes.deserializeWithType(p, ctxt, typeDeser);
}
if (useObjectId) {
referringAccumulator.put(key, value);
} else {
result.put(key, value);
}
} catch (UnresolvedForwardReference reference) {
handleUnresolvedReference(p, referringAccumulator, key, reference);
} catch (Exception e) {
wrapAndThrow(e, result, key);
}
}
// 23-Mar-2015, tatu: TODO: verify we got END_OBJECT?
}
@SuppressWarnings("unchecked")
public Map<Object,Object> _deserializeUsingCreator(JsonParser p, DeserializationContext ctxt) throws IOException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
// null -> no ObjectIdReader for Maps (yet?)
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, null);
final JsonDeserializer<Object> valueDes = _valueDeserializer;
final TypeDeserializer typeDeser = _valueTypeDeserializer;
String key;
if (p.isExpectedStartObjectToken()) {
key = p.nextFieldName();
} else if (p.hasToken(JsonToken.FIELD_NAME)) {
key = p.getCurrentName();
} else {
key = null;
}
for (; key != null; key = p.nextFieldName()) {
JsonToken t = p.nextToken(); // to get to value
if (_ignorableProperties != null && _ignorableProperties.contains(key)) {
p.skipChildren(); // and skip it (in case of array/object)
continue;
}
// creator property?
SettableBeanProperty prop = creator.findCreatorProperty(key);
if (prop != null) {
// Last property to set?
if (buffer.assignParameter(prop, prop.deserialize(p, ctxt))) {
p.nextToken();
Map<Object,Object> result;
try {
result = (Map<Object,Object>)creator.build(ctxt, buffer);
} catch (Exception e) {
wrapAndThrow(e, _mapType.getRawClass(), key);
return null;
}
_
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>readAndBind(p, ctxt, result);
return result;
}
continue;
}
// other property? needs buffering
Object actualKey = _keyDeserializer.deserializeKey(key, ctxt);
Object value;
try {
if (t == JsonToken.VALUE_NULL) {
value = valueDes.getNullValue(ctxt);
} else if (typeDeser == null) {
value = valueDes.deserialize(p, ctxt);
} else {
value = valueDes.deserializeWithType(p, ctxt, typeDeser);
}
} catch (Exception e) {
wrapAndThrow(e, _mapType.getRawClass(), key);
return null;
}
buffer.bufferMapProperty(actualKey, value);
}
// end of JSON object?
// if so, can just construct and leave...
try {
return (Map<Object,Object>)creator.build(ctxt, buffer);
} catch (Exception e) {
wrapAndThrow(e, _mapType.getRawClass(), null);
return null;
}
}
@Deprecated // since 2.5
protected void wrapAndThrow(Throwable t, Object ref) throws IOException {
wrapAndThrow(t, ref, null);
}
private void handleUnresolvedReference(JsonParser jp, MapReferringAccumulator accumulator,
Object key, UnresolvedForwardReference reference)
throws JsonMappingException
{
if (accumulator == null) {
throw JsonMappingException.from(jp, "Unresolved forward reference but no identity info.", reference);
}
Referring referring = accumulator.handleUnresolvedReference(reference, key);
reference.getRoid().appendReferring(referring);
}
private final static class MapReferringAccumulator {
private final Class<?> _valueType;
private Map<Object,Object> _result;
/**
* A list of {@link MapReferring} to maintain ordering.
*/
private List<MapReferring> _accumulator = new ArrayList<MapReferring>();
public MapReferringAccumulator(Class<?> valueType, Map<Object, Object> result) {
_valueType = valueType;
_result = result;
}
public void put(Object key, Object value)
{
if (_accumulator.isEmpty()) {
_result.put(key, value);
} else {
MapReferring ref = _accumulator.get(_accumulator.size() - 1);
ref.next.put(key, value);
}
}
public Referring handleUnresolvedReference(UnresolvedForwardReference reference, Object key)
{
MapReferring id = new MapReferring(this, reference, _valueType, key);
_accumulator.add(id);
return id;
}
public void resolveForwardReference(Object id, Object value) throws IOException
{
Iterator<MapReferring> iterator = _accumulator.iterator();
// Resolve ordering after resolution of an id. This means either:
// 1- adding to the result map in case of the first unresolved id.
// 2- merge the content of the resolved id with its previous unresolved id.
Map<Object,Object> previous = _result;
while (iterator.hasNext()) {
MapReferring ref = iterator.next();
if (ref.hasId(id)) {
iterator.remove();
previous.put(ref.key, value);
previous.putAll(ref.next);
return;
}
previous = ref.next;
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> new BuilderBasedDeserializer(this, ignorableProps);
}
@Override
protected BeanAsArrayBuilderDeserializer asArrayDeserializer() {
SettableBeanProperty[] props = _beanProperties.getPropertiesInInsertionOrder();
return new BeanAsArrayBuilderDeserializer(this, props, _buildMethod);
}
/*
/**********************************************************
/* JsonDeserializer implementation
/**********************************************************
*/
protected final Object finishBuild(DeserializationContext ctxt, Object builder)
throws IOException
{
// As per [databind#777], allow returning builder itself
if (null == _buildMethod) {
return builder;
}
try {
return _buildMethod.getMember().invoke(builder);
} catch (Exception e) {
wrapInstantiationProblem(e, ctxt);
return null;
}
}
/**
* Main deserialization method for bean-based objects (POJOs).
*/
@Override
public final Object deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
JsonToken t = jp.getCurrentToken();
// common case first:
if (t == JsonToken.START_OBJECT) {
t = jp.nextToken();
if (_vanillaProcessing) {
return finishBuild(ctxt, vanillaDeserialize(jp, ctxt, t));
}
Object builder = deserializeFromObject(jp, ctxt);
return finishBuild(ctxt, builder);
}
// and then others, generally requiring use of @JsonCreator
switch (t) {
case VALUE_STRING:
return finishBuild(ctxt, deserializeFromString(jp, ctxt));
case VALUE_NUMBER_INT:
return finishBuild(ctxt, deserializeFromNumber(jp, ctxt));
case VALUE_NUMBER_FLOAT:
return finishBuild(ctxt, deserializeFromDouble(jp, ctxt));
case VALUE_EMBEDDED_OBJECT:
return jp.getEmbeddedObject();
case VALUE_TRUE:
case VALUE_FALSE:
return finishBuild(ctxt, deserializeFromBoolean(jp, ctxt));
case START_ARRAY:
// these only work if there's a (delegating) creator...
return finishBuild(ctxt, deserializeFromArray(jp, ctxt));
case FIELD_NAME:
case END_OBJECT: // added to resolve [JACKSON-319], possible related issues
return finishBuild(ctxt, deserializeFromObject(jp, ctxt));
default:
throw ctxt.mappingException(handledType());
}
}
/**
* Secondary deserialization method, called in cases where POJO
* instance is created as part of deserialization, potentially
* after collecting some or all of the properties to set.
*/
@Override
public Object deserialize(JsonParser jp, DeserializationContext ctxt,
Object builder)
throws IOException, JsonProcessingException
{
/* Important: we call separate method which does NOT call
* 'finishBuild()', to avoid problems with recursion
*/
return finishBuild(ctxt, _deserialize(jp, ctxt, builder));
}
/*
/**********************************************************
/* Concrete deserialization methods
/**********************************************************
*/
protected final Object _deserialize(JsonParser jp,
DeserializationContext ctxt, Object builder)
throws IOException, JsonProcessingException
{
if (_injectables != null) {
injectValues(ctxt, builder);
}
if (_unwrappedPropertyHandler != null) {
return deserializeWithUnwrapped(jp, ctxt, builder);
}
if (_externalTypeIdHandler != null) {
return deserializeWithExternalTypeId(jp, ctxt, builder
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>);
}
if (_needViewProcesing) {
Class<?> view = ctxt.getActiveView();
if (view != null) {
return deserializeWithView(jp, ctxt, builder, view);
}
}
JsonToken t = jp.getCurrentToken();
// 23-Mar-2010, tatu: In some cases, we start with full JSON object too...
if (t == JsonToken.START_OBJECT) {
t = jp.nextToken();
}
for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) {
String propName = jp.getCurrentName();
// Skip field name:
jp.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
try {
builder = prop.deserializeSetAndReturn(jp, ctxt, builder);
} catch (Exception e) {
wrapAndThrow(e, builder, propName, ctxt);
}
continue;
}
handleUnknownVanilla(jp, ctxt, handledType(), propName);
}
return builder;
}
/**
* Streamlined version that is only used when no "special"
* features are enabled.
*/
private final Object vanillaDeserialize(JsonParser jp,
DeserializationContext ctxt, JsonToken t)
throws IOException, JsonProcessingException
{
Object bean = _valueInstantiator.createUsingDefault(ctxt);
for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
String propName = jp.getCurrentName();
// Skip field name:
jp.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
try {
bean = prop.deserializeSetAndReturn(jp, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
} else {
handleUnknownVanilla(jp, ctxt, bean, propName);
}
}
return bean;
}
/**
* General version used when handling needs more advanced
* features.
*/
@Override
public Object deserializeFromObject(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
if (_nonStandardCreation) {
if (_unwrappedPropertyHandler != null) {
return deserializeWithUnwrapped(jp, ctxt);
}
if (_externalTypeIdHandler != null) {
return deserializeWithExternalTypeId(jp, ctxt);
}
return deserializeFromObjectUsingNonDefault(jp, ctxt);
}
Object bean = _valueInstantiator.createUsingDefault(ctxt);
if (_injectables != null) {
injectValues(ctxt, bean);
}
if (_needViewProcesing) {
Class<?> view = ctxt.getActiveView();
if (view != null) {
return deserializeWithView(jp, ctxt, bean, view);
}
}
for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
String propName = jp.getCurrentName();
// Skip field name:
jp.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
try {
bean = prop.deserializeSetAndReturn(jp, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>);
}
continue;
}
handleUnknownVanilla(jp, ctxt, bean, propName);
}
return bean;
}
/**
* Method called to deserialize bean using "property-based creator":
* this means that a non-default constructor or factory method is
* called, and then possibly other setters. The trick is that
* values for creator method need to be buffered, first; and
* due to non-guaranteed ordering possibly some other properties
* as well.
*/
@Override
@SuppressWarnings("resource")
protected final Object _deserializeUsingPropertyBased(final JsonParser jp,
final DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(jp, ctxt, _objectIdReader);
// 04-Jan-2010, tatu: May need to collect unknown properties for polymorphic cases
TokenBuffer unknown = null;
JsonToken t = jp.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) {
String propName = jp.getCurrentName();
jp.nextToken(); // to point to value
// creator property?
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null) {
// Last creator property to set?
if (buffer.assignParameter(creatorProp, creatorProp.deserialize(jp, ctxt))) {
jp.nextToken(); // to move to following FIELD_NAME/END_OBJECT
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
continue; // never gets here
}
// polymorphic?
if (bean.getClass() != _beanType.getRawClass()) {
return handlePolymorphic(jp, ctxt, bean, unknown);
}
if (unknown != null) { // nope, just extra unknown stuff...
bean = handleUnknownProperties(ctxt, bean, unknown);
}
// or just clean?
return _deserialize(jp, ctxt, bean);
}
continue;
}
// Object Id property?
if (buffer.readIdProperty(propName)) {
continue;
}
// regular property? needs buffering
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
buffer.bufferProperty(prop, prop.deserialize(jp, ctxt));
continue;
}
// As per [JACKSON-313], things marked as ignorable should not be
// passed to any setter
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(jp, ctxt, handledType(), propName);
continue;
}
// "any property"?
if (_anySetter != null) {
buffer.bufferAnyProperty(_anySetter, propName, _anySetter.deserialize(jp, ctxt));
continue;
}
// Ok then, let's collect the whole field; name and value
if (unknown == null) {
unknown = new TokenBuffer(jp, ctxt);
}
unknown.writeFieldName(propName);
unknown.copyCurrentStructure(jp);
}
// We hit END_OBJECT, so:
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> (Exception e) {
wrapInstantiationProblem(e, ctxt);
return null; // never gets here
}
if (unknown != null) {
// polymorphic?
if (bean.getClass() != _beanType.getRawClass()) {
return handlePolymorphic(null, ctxt, bean, unknown);
}
// no, just some extra unknown properties
return handleUnknownProperties(ctxt, bean, unknown);
}
return bean;
}
/*
/**********************************************************
/* Deserializing when we have to consider an active View
/**********************************************************
*/
protected final Object deserializeWithView(JsonParser jp, DeserializationContext ctxt,
Object bean, Class<?> activeView)
throws IOException, JsonProcessingException
{
JsonToken t = jp.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) {
String propName = jp.getCurrentName();
// Skip field name:
jp.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
if (!prop.visibleInView(activeView)) {
jp.skipChildren();
continue;
}
try {
bean = prop.deserializeSetAndReturn(jp, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
handleUnknownVanilla(jp, ctxt, bean, propName);
}
return bean;
}
/*
/**********************************************************
/* Handling for cases where we have "unwrapped" values
/**********************************************************
*/
/**
* Method called when there are declared "unwrapped" properties
* which need special handling
*/
@SuppressWarnings("resource")
protected Object deserializeWithUnwrapped(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
if (_delegateDeserializer != null) {
return _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.deserialize(jp, ctxt));
}
if (_propertyBasedCreator != null) {
return deserializeUsingPropertyBasedWithUnwrapped(jp, ctxt);
}
TokenBuffer tokens = new TokenBuffer(jp, ctxt);
tokens.writeStartObject();
Object bean = _valueInstantiator.createUsingDefault(ctxt);
if (_injectables != null) {
injectValues(ctxt, bean);
}
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
String propName = jp.getCurrentName();
jp.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
if (activeView != null && !prop.visibleInView(activeView)) {
jp.skipChildren();
continue;
}
try {
bean = prop.deserializeSetAndReturn(jp, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
// ignorable things should be ignored
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(jp, ctxt, bean, propName);
continue;
}
// but... others should be passed to unwrapped property deserializers
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(jp);
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> // how about any setter? We'll get copies but...
if (_anySetter != null) {
try {
_anySetter.deserializeAndSet(jp, ctxt, bean, propName);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
}
tokens.writeEndObject();
_unwrappedPropertyHandler.processUnwrapped(jp, ctxt, bean, tokens);
return bean;
}
@SuppressWarnings("resource")
protected Object deserializeWithUnwrapped(JsonParser jp,
DeserializationContext ctxt, Object bean)
throws IOException, JsonProcessingException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.START_OBJECT) {
t = jp.nextToken();
}
TokenBuffer tokens = new TokenBuffer(jp, ctxt);
tokens.writeStartObject();
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) {
String propName = jp.getCurrentName();
SettableBeanProperty prop = _beanProperties.find(propName);
jp.nextToken();
if (prop != null) { // normal case
if (activeView != null && !prop.visibleInView(activeView)) {
jp.skipChildren();
continue;
}
try {
bean = prop.deserializeSetAndReturn(jp, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(jp, ctxt, bean, propName);
continue;
}
// but... others should be passed to unwrapped property deserializers
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(jp);
// how about any setter? We'll get copies but...
if (_anySetter != null) {
_anySetter.deserializeAndSet(jp, ctxt, bean, propName);
}
}
tokens.writeEndObject();
_unwrappedPropertyHandler.processUnwrapped(jp, ctxt, bean, tokens);
return bean;
}
@SuppressWarnings("resource")
protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p,
DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
JsonToken t = p.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken(); // to point to value
// creator property?
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null) {
// Last creator property to set?
if (buffer.assignParameter(creatorProp, creatorProp.deserialize(p, ctxt))) {
t = p.nextToken(); // to move to following FIELD_NAME/END_OBJECT
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
continue; //
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> never gets here
}
// if so, need to copy all remaining tokens into buffer
while (t == JsonToken.FIELD_NAME) {
p.nextToken(); // to skip name
tokens.copyCurrentStructure(p);
t = p.nextToken();
}
tokens.writeEndObject();
if (bean.getClass() != _beanType.getRawClass()) {
// !!! 08-Jul-2011, tatu: Could probably support; but for now
// it's too complicated, so bail out
throw ctxt.mappingException("Can not create polymorphic instances with unwrapped values");
}
return _unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
}
continue;
}
// Object Id property?
if (buffer.readIdProperty(propName)) {
continue;
}
// regular property? needs buffering
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
buffer.bufferProperty(prop, prop.deserialize(p, ctxt));
continue;
}
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt, handledType(), propName);
continue;
}
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(p);
// "any property"?
if (_anySetter != null) {
buffer.bufferAnyProperty(_anySetter, propName, _anySetter.deserialize(p, ctxt));
}
}
// We hit END_OBJECT, so:
Object bean;
// !!! 15-Feb-2012, tatu: Need to modify creator to use Builder!
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapInstantiationProblem(e, ctxt);
return null; // never gets here
}
return _unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
}
/*
/**********************************************************
/* Handling for cases where we have property/-ies with
/* external type id
/**********************************************************
*/
protected Object deserializeWithExternalTypeId(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
if (_propertyBasedCreator != null) {
return deserializeUsingPropertyBasedWithExternalTypeId(jp, ctxt);
}
return deserializeWithExternalTypeId(jp, ctxt, _valueInstantiator.createUsingDefault(ctxt));
}
protected Object deserializeWithExternalTypeId(JsonParser jp,
DeserializationContext ctxt, Object bean)
throws IOException, JsonProcessingException
{
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
final ExternalTypeHandler ext = _externalTypeIdHandler.start();
for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
String propName = jp.getCurrentName();
jp.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
if (activeView != null && !prop.visibleInView(activeView)) {
jp.skipChildren();
continue;
}
try {
bean = prop.deserializeSetAndReturn(jp, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
// ignorable things should be ignored
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.PropertyName;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.Annotations;
/**
* This concrete sub-class implements Collection or Map property that is
* indirectly by getting the property value and directly modifying it.
*/
public final class SetterlessProperty
extends SettableBeanProperty
{
private static final long serialVersionUID = 1L;
protected final AnnotatedMethod _annotated;
/**
* Get method for accessing property value used to access property
* (of Collection or Map type) to modify.
*/
protected final Method _getter;
public SetterlessProperty(BeanPropertyDefinition propDef, JavaType type,
TypeDeserializer typeDeser, Annotations contextAnnotations, AnnotatedMethod method) {
super(propDef, type, typeDeser, contextAnnotations);
_annotated = method;
_getter = method.getAnnotated();
}
protected SetterlessProperty(SetterlessProperty src, JsonDeserializer<?> deser) {
super(src, deser);
_annotated = src._annotated;
_getter = src._getter;
}
protected SetterlessProperty(SetterlessProperty src, PropertyName newName) {
super(src, newName);
_annotated = src._annotated;
_getter = src._getter;
}
@Override
public SetterlessProperty withName(PropertyName newName) {
return new SetterlessProperty(this, newName);
}
@Override
public SetterlessProperty withValueDeserializer(JsonDeserializer<?> deser) {
return new SetterlessProperty(this, deser);
}
/*
/**********************************************************
/* BeanProperty impl
/**********************************************************
*/
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return _annotated.getAnnotation(acls);
}
@Override public AnnotatedMember getMember() { return _annotated; }
/*
/**********************************************************
/* Overridden methods
/**********************************************************
*/
@Override
public final void deserializeAndSet(JsonParser jp, DeserializationContext ctxt,
Object instance)
throws IOException, JsonProcessingException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NULL) {
/* Hmmh. Is this a problem? We won't be setting anything, so it's
* equivalent of empty Collection/Map in this case
*/
return;
}
// For [#501] fix we need to implement this but:
if (_valueTypeDeserializer != null) {
throw new JsonMapping
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>.
*/
@Override
public SettableBeanProperty findBackReference(String logicalName) {
return (_backRefProperties == null) ? null : _backRefProperties.get(logicalName);
}
/*
/**********************************************************
/* Deserializer implementation
/**********************************************************
*/
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt,
TypeDeserializer typeDeserializer)
throws IOException, JsonProcessingException
{
// Hmmh. One tricky question; for scalar, is it an Object Id, or "Natural" type?
// for now, prefer Object Id:
if (_objectIdReader != null) {
JsonToken t = jp.getCurrentToken();
// should be good enough check; we only care about Strings, integral numbers:
if (t != null && t.isScalarValue()) {
return _deserializeFromObjectId(jp, ctxt);
}
}
// First: support "natural" values (which are always serialized without type info!)
Object result = _deserializeIfNatural(jp, ctxt);
if (result != null) {
return result;
}
return typeDeserializer.deserializeTypedFromObject(jp, ctxt);
}
@Override
public Object deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
// This method should never be called...
throw ctxt.instantiationException(_baseType.getRawClass(),
"abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information");
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected Object _deserializeIfNatural(JsonParser jp, DeserializationContext ctxt) throws IOException
{
/* As per [JACKSON-417], there is a chance we might be "natural" types
* (String, Boolean, Integer, Double), which do not include any type information...
* Care must be taken to only return this if return type matches, however.
* Finally, we may have to consider possibility of custom handlers for
* these values: but for now this should work ok.
*/
switch (jp.getCurrentTokenId()) {
case JsonTokenId.ID_STRING:
if (_acceptString) {
return jp.getText();
}
break;
case JsonTokenId.ID_NUMBER_INT:
if (_acceptInt) {
return jp.getIntValue();
}
break;
case JsonTokenId.ID_NUMBER_FLOAT:
if (_acceptDouble) {
return Double.valueOf(jp.getDoubleValue());
}
break;
case JsonTokenId.ID_TRUE:
if (_acceptBoolean) {
return Boolean.TRUE;
}
break;
case JsonTokenId.ID_FALSE:
if (_acceptBoolean) {
return Boolean.FALSE;
}
break;
}
return null;
}
/**
* Method called in cases where it looks like we got an Object Id
* to parse and use as a reference.
*/
protected Object _deserializeFromObjectId(JsonParser jp, DeserializationContext ctxt) throws IOException
{
Object id = _objectIdReader.readObjectReference(jp, ctxt);
ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver);
// do we have it resolved?
Object pojo = roid.resolve();
if (pojo == null) { // not yet; should wait...
throw new UnresolvedForwardReference("Could not resolve Object
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> new SimpleType(subclass, _typeNames, _typeParameters, _valueHandler, _typeHandler,
_asStatic, _typeParametersFor);
}
@Override
public JavaType narrowContentsBy(Class<?> subclass)
{
// should never get called
throw new IllegalArgumentException("Internal error: SimpleType.narrowContentsBy() should never be called");
}
@Override
public JavaType widenContentsBy(Class<?> subclass)
{
// should never get called
throw new IllegalArgumentException("Internal error: SimpleType.widenContentsBy() should never be called");
}
public static SimpleType construct(Class<?> cls)
{
/* Let's add sanity checks, just to ensure no
* Map/Collection entries are constructed
*/
if (Map.class.isAssignableFrom(cls)) {
throw new IllegalArgumentException("Can not construct SimpleType for a Map (class: "+cls.getName()+")");
}
if (Collection.class.isAssignableFrom(cls)) {
throw new IllegalArgumentException("Can not construct SimpleType for a Collection (class: "+cls.getName()+")");
}
// ... and while we are at it, not array types either
if (cls.isArray()) {
throw new IllegalArgumentException("Can not construct SimpleType for an array (class: "+cls.getName()+")");
}
return new SimpleType(cls);
}
@Override
public SimpleType withTypeHandler(Object h)
{
return new SimpleType(_class, _typeNames, _typeParameters, _valueHandler, h, _asStatic, _typeParametersFor);
}
@Override
public JavaType withContentTypeHandler(Object h) {
// no content type, so:
throw new IllegalArgumentException("Simple types have no content types; can not call withContenTypeHandler()");
}
@Override
public SimpleType withValueHandler(Object h) {
if (h == _valueHandler) {
return this;
}
return new SimpleType(_class, _typeNames, _typeParameters, h, _typeHandler, _asStatic, _typeParametersFor);
}
@Override
public SimpleType withContentValueHandler(Object h) {
// no content type, so:
throw new IllegalArgumentException("Simple types have no content types; can not call withContenValueHandler()");
}
@Override
public SimpleType withStaticTyping() {
return _asStatic ? this : new SimpleType(_class,
_typeNames, _typeParameters, _valueHandler, _typeHandler, true, _typeParametersFor);
}
@Override
protected String buildCanonicalName()
{
StringBuilder sb = new StringBuilder();
sb.append(_class.getName());
if (_typeParameters != null && _typeParameters.length > 0) {
sb.append('<');
boolean first = true;
for (JavaType t : _typeParameters) {
if (first) {
first = false;
} else {
sb.append(',');
}
sb.append(t.toCanonical());
}
sb.append('>');
}
return sb.toString();
}
/*
/**********************************************************
/* Public API
/**********************************************************
*/
@Override
public boolean isContainerType() { return false; }
@Override
public int containedTypeCount() {
return (_typeParameters == null) ? 0 : _typeParameters.length;
}
@Override
public JavaType containedType(int index)
{
if (index < 0 || _typeParameters == null || index
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.util.ClassUtil;
/**
* This sub-class is used to handle special case of value being a
* non-static inner class. If so, we will have to use a special
* alternative for default constructor; but otherwise can delegate
* to regular implementation.
*/
public final class InnerClassProperty
extends SettableBeanProperty
{
private static final long serialVersionUID = 1L;
/**
* Actual property that we use after value construction.
*/
protected final SettableBeanProperty _delegate;
/**
* Constructor used when deserializing this property.
* Transient since there is no need to persist; only needed during
* construction of objects.
*/
final protected transient Constructor<?> _creator;
/**
* Serializable version of single-arg constructor we use for value instantiation.
*/
protected AnnotatedConstructor _annotated;
public InnerClassProperty(SettableBeanProperty delegate,
Constructor<?> ctor)
{
super(delegate);
_delegate = delegate;
_creator = ctor;
}
/**
* Constructor used with JDK Serialization; needed to handle transient
* Constructor, wrap/unwrap in/out-of Annotated variant.
*/
protected InnerClassProperty(InnerClassProperty src, AnnotatedConstructor ann)
{
super(src);
_delegate = src._delegate;
_annotated = ann;
_creator = (_annotated == null) ? null : _annotated.getAnnotated();
if (_creator == null) {
throw new IllegalArgumentException("Missing constructor (broken JDK (de)serialization?)");
}
}
protected InnerClassProperty(InnerClassProperty src, JsonDeserializer<?> deser)
{
super(src, deser);
_delegate = src._delegate.withValueDeserializer(deser);
_creator = src._creator;
}
protected InnerClassProperty(InnerClassProperty src, PropertyName newName) {
super(src, newName);
_delegate = src._delegate.withName(newName);
_creator = src._creator;
}
@Override
public InnerClassProperty withName(PropertyName newName) {
return new InnerClassProperty(this, newName);
}
@Override
public InnerClassProperty withValueDeserializer(JsonDeserializer<?> deser) {
return new InnerClassProperty(this, deser);
}
// // // BeanProperty impl
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return _delegate.getAnnotation(acls);
}
@Override public AnnotatedMember getMember() { return _delegate.getMember(); }
/*
/**********************************************************
/* Deserialization methods
/**********************************************************
*/
@Override
public void deserializeAndSet(JsonParser jp, DeserializationContext ctxt, Object bean)
throws IOException
{
JsonToken t = jp.getCurrentToken();
Object value;
if (t == JsonToken.VALUE_NULL) {
value = _valueDeserializer.getNullValue(ctxt);
} else if (_valueTypeDeserializer != null) {
value = _valueDeserializer.deserializeWithType(jp, ctxt, _
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
@JacksonStdImpl
public final class StringDeserializer extends StdScalarDeserializer<String>
{
private static final long serialVersionUID = 1L;
/**
* @since 2.2
*/
public final static StringDeserializer instance = new StringDeserializer();
public StringDeserializer() { super(String.class); }
// since 2.6, slightly faster lookups for this very common type
@Override
public boolean isCachable() { return true; }
@Override
public String deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
JsonToken curr = jp.getCurrentToken();
if (curr == JsonToken.VALUE_STRING) {
return jp.getText();
}
// Issue#381
if (curr == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final String parsed = _parseString(jp, ctxt);
if (jp.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'String' value but there was more than a single value in the array");
}
return parsed;
}
// [JACKSON-330]: need to gracefully handle byte[] data, as base64
if (curr == JsonToken.VALUE_EMBEDDED_OBJECT) {
Object ob = jp.getEmbeddedObject();
if (ob == null) {
return null;
}
if (ob instanceof byte[]) {
return Base64Variants.getDefaultVariant().encode((byte[]) ob, false);
}
// otherwise, try conversion using toString()...
return ob.toString();
}
// allow coercions for other scalar types
String text = jp.getValueAsString();
if (text != null) {
return text;
}
throw ctxt.mappingException(_valueClass, curr);
}
// 1.6: since we can never have type info ("natural type"; String, Boolean, Integer, Double):
// (is it an error to even call this version?)
@Override
public String deserializeWithType(JsonParser jp, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException {
return deserialize(jp, ctxt);
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> == valueTypeDeser)) {
return this;
}
return new MapEntryDeserializer(this,
keyDeser, (JsonDeserializer<Object>) valueDeser, valueTypeDeser);
}
/*
/**********************************************************
/* Validation, post-processing (ResolvableDeserializer)
/**********************************************************
*/
/**
* Method called to finalize setup of this deserializer,
* when it is known for which property deserializer is needed for.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
KeyDeserializer kd = _keyDeserializer;
if (kd == null) {
kd = ctxt.findKeyDeserializer(_type.containedType(0), property);
} else {
if (kd instanceof ContextualKeyDeserializer) {
kd = ((ContextualKeyDeserializer) kd).createContextual(ctxt, property);
}
}
JsonDeserializer<?> vd = _valueDeserializer;
vd = findConvertingContentDeserializer(ctxt, property, vd);
JavaType contentType = _type.containedType(1);
if (vd == null) {
vd = ctxt.findContextualValueDeserializer(contentType, property);
} else { // if directly assigned, probably not yet contextual, so:
vd = ctxt.handleSecondaryContextualization(vd, property, contentType);
}
TypeDeserializer vtd = _valueTypeDeserializer;
if (vtd != null) {
vtd = vtd.forProperty(property);
}
return withResolved(kd, vtd, vd);
}
/*
/**********************************************************
/* ContainerDeserializerBase API
/**********************************************************
*/
@Override
public JavaType getContentType() {
return _type.containedType(1);
}
@Override
public JsonDeserializer<Object> getContentDeserializer() {
return _valueDeserializer;
}
/*
/**********************************************************
/* JsonDeserializer API
/**********************************************************
*/
@Override
public Map.Entry<Object,Object> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// Ok: must point to START_OBJECT, FIELD_NAME or END_OBJECT
JsonToken t = jp.getCurrentToken();
if (t != JsonToken.START_OBJECT && t != JsonToken.FIELD_NAME && t != JsonToken.END_OBJECT) {
// [JACKSON-620] (empty) String may be ok however:
// slightly redundant (since String was passed above), but
return _deserializeFromEmpty(jp, ctxt);
}
if (t == JsonToken.START_OBJECT) {
t = jp.nextToken();
}
if (t != JsonToken.FIELD_NAME) {
if (t == JsonToken.END_OBJECT) {
throw ctxt.mappingException("Can not deserialize a Map.Entry out of empty JSON Object");
}
throw ctxt.mappingException(handledType(), t);
}
final KeyDeserializer keyDes = _keyDeserializer;
final JsonDeserializer<Object> valueDes = _valueDeserializer;
final TypeDeserializer typeDeser = _valueTypeDeserializer;
final String keyStr = jp.getCurrentName();
Object key = keyDes.deserializeKey(keyStr, ctxt);
Object value = null;
// And then the value...
t = jp.nextToken();
try {
// Note: must handle null explicitly here; value deserializers won't
if (t == JsonToken.VALUE_NULL) {
value = valueDes.
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>getNullValue(ctxt);
} else if (typeDeser == null) {
value = valueDes.deserialize(jp, ctxt);
} else {
value = valueDes.deserializeWithType(jp, ctxt, typeDeser);
}
} catch (Exception e) {
wrapAndThrow(e, Map.Entry.class, keyStr);
}
// Close, but also verify that we reached the END_OBJECT
t = jp.nextToken();
if (t != JsonToken.END_OBJECT) {
if (t == JsonToken.FIELD_NAME) { // most likely
throw ctxt.mappingException("Problem binding JSON into Map.Entry: more than one entry in JSON (second field: '"+jp.getCurrentName()+"')");
}
// how would this occur?
throw ctxt.mappingException("Problem binding JSON into Map.Entry: unexpected content after JSON Object entry: "+t);
}
return new AbstractMap.SimpleEntry<Object,Object>(key, value);
}
@Override
public Map.Entry<Object,Object> deserialize(JsonParser jp, DeserializationContext ctxt,
Map.Entry<Object,Object> result) throws IOException
{
throw new IllegalStateException("Can not update Map.Entry values");
}
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt,
TypeDeserializer typeDeserializer)
throws IOException, JsonProcessingException
{
// In future could check current token... for now this should be enough:
return typeDeserializer.deserializeTypedFromObject(jp, ctxt);
}
/*
/**********************************************************
/* Other public accessors
/**********************************************************
*/
@Override public JavaType getValueType() { return _type; }
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> */
protected transient HierarchicType _cachedArrayListType;
/*
/**********************************************************
/* Configuration
/**********************************************************
*/
/**
* Registered {@link TypeModifier}s: objects that can change details
* of {@link JavaType} instances factory constructs.
*/
protected final TypeModifier[] _modifiers;
protected final TypeParser _parser;
/**
* ClassLoader used by this factory (Issue #624)
*/
protected final ClassLoader _classLoader;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
private TypeFactory() {
_parser = new TypeParser(this);
_modifiers = null;
_classLoader = null;
}
protected TypeFactory(TypeParser p, TypeModifier[] mods) {
this(p, mods, null);
}
protected TypeFactory(TypeParser p, TypeModifier[] mods, ClassLoader classLoader) {
// As per [databind#894] must ensure we have back-linkage from TypeFactory:
_parser = p.withFactory(this);
_modifiers = mods;
_classLoader = classLoader;
}
public TypeFactory withModifier(TypeModifier mod)
{
if (mod == null) { // mostly for unit tests
return new TypeFactory(_parser, _modifiers, _classLoader);
}
if (_modifiers == null) {
return new TypeFactory(_parser, new TypeModifier[] { mod }, _classLoader);
}
return new TypeFactory(_parser, ArrayBuilders.insertInListNoDup(_modifiers, mod), _classLoader);
}
public TypeFactory withClassLoader(ClassLoader classLoader) {
return new TypeFactory(_parser, _modifiers, classLoader);
}
/**
* Method used to access the globally shared instance, which has
* no custom configuration. Used by <code>ObjectMapper</code> to
* get the default factory when constructed.
*/
public static TypeFactory defaultInstance() { return instance; }
/**
* Method that will clear up any cached type definitions that may
* be cached by this {@link TypeFactory} instance.
* This method should not be commonly used, that is, only use it
* if you know there is a problem with retention of type definitions;
* the most likely (and currently only known) problem is retention
* of {@link Class} instances via {@link JavaType} reference.
*
* @since 2.4.1
*/
public void clearCache() {
_typeCache.clear();
}
/*
* Getters
*/
public ClassLoader getClassLoader() {
return _classLoader;
}
/*
/**********************************************************
/* Static methods for non-instance-specific functionality
/**********************************************************
*/
/**
* Method for constructing a marker type that indicates missing generic
* type information, which is handled same as simple type for
* <code>java.lang.Object</code>.
*/
public static JavaType unknownType() {
return defaultInstance()._unknownType();
}
/**
* Static helper method that can be called to figure out type-erased
* call for given JDK type. It can be called statically since type resolution
* process can never change actual type-erased class; thereby static
* default instance is used for determination.
*/
public static Class<?> rawClass(Type t) {
if (t instanceof Class<?>) {
return (Class<?>) t;
}
// Shouldbe able to optimize bit more in future...
return
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> defaultInstance().constructType(t).getRawClass();
}
/*
/**********************************************************
/* Low-level helper methods
/**********************************************************
*/
/**
* Low-level lookup method moved from {@link com.fasterxml.jackson.databind.util.ClassUtil},
* to allow for overriding of lookup functionality in environments like OSGi.
*
* @since 2.6
*/
public Class<?> findClass(String className) throws ClassNotFoundException
{
if (className.indexOf('.') < 0) {
Class<?> prim = _findPrimitive(className);
if (prim != null) {
return prim;
}
}
// Two-phase lookup: first using context ClassLoader; then default
Throwable prob = null;
ClassLoader loader = this.getClassLoader();
if (loader == null) {
loader = Thread.currentThread().getContextClassLoader();
}
if (loader != null) {
try {
return classForName(className, true, loader);
} catch (Exception e) {
prob = ClassUtil.getRootCause(e);
}
}
try {
return classForName(className);
} catch (Exception e) {
if (prob == null) {
prob = ClassUtil.getRootCause(e);
}
}
if (prob instanceof RuntimeException) {
throw (RuntimeException) prob;
}
throw new ClassNotFoundException(prob.getMessage(), prob);
}
protected Class<?> classForName(String name, boolean initialize,
ClassLoader loader) throws ClassNotFoundException {
return Class.forName(name, true, loader);
}
protected Class<?> classForName(String name) throws ClassNotFoundException {
return Class.forName(name);
}
protected Class<?> _findPrimitive(String className)
{
if ("int".equals(className)) return Integer.TYPE;
if ("long".equals(className)) return Long.TYPE;
if ("float".equals(className)) return Float.TYPE;
if ("double".equals(className)) return Double.TYPE;
if ("boolean".equals(className)) return Boolean.TYPE;
if ("byte".equals(className)) return Byte.TYPE;
if ("char".equals(className)) return Character.TYPE;
if ("short".equals(className)) return Short.TYPE;
if ("void".equals(className)) return Void.TYPE;
return null;
}
/*
/**********************************************************
/* Type conversion, parameterization resolution methods
/**********************************************************
*/
/**
* Factory method for creating a subtype of given base type, as defined
* by specified subclass; but retaining generic type information if any.
* Can be used, for example, to get equivalent of "HashMap<String,Integer>"
* from "Map<String,Integer>" by giving <code>HashMap.class</code>
* as subclass.
*/
public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass)
{
// simple optimization to avoid costly introspection if type-erased type does NOT differ
if (baseType.getRawClass() == subclass) {
return baseType;
}
// Currently only SimpleType instances can become something else
if (baseType instanceof SimpleType) {
// and only if subclass is an array, Collection or Map
if (subclass.isArray()
|| Map.class.isAssignableFrom(subclass)
|| Collection.class.isAssignableFrom(subclass)) {
// need to assert type compatibility...
if (!baseType.getRawClass().
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> if (sup != null) {
sup.setSubType(current);
current.setSuperType(sup);
return current;
}
}
return null;
}
protected synchronized HierarchicType _hashMapSuperInterfaceChain(HierarchicType current)
{
if (_cachedHashMapType == null) {
HierarchicType base = current.deepCloneWithoutSubtype();
_doFindSuperInterfaceChain(base, Map.class);
_cachedHashMapType = base.getSuperType();
}
HierarchicType t = _cachedHashMapType.deepCloneWithoutSubtype();
current.setSuperType(t);
t.setSubType(current);
return current;
}
protected synchronized HierarchicType _arrayListSuperInterfaceChain(HierarchicType current)
{
if (_cachedArrayListType == null) {
HierarchicType base = current.deepCloneWithoutSubtype();
_doFindSuperInterfaceChain(base, List.class);
_cachedArrayListType = base.getSuperType();
}
HierarchicType t = _cachedArrayListType.deepCloneWithoutSubtype();
current.setSuperType(t);
t.setSubType(current);
return current;
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>.6
*/
public void serializePolymorphic(JsonGenerator gen, Object value, JavaType rootType,
JsonSerializer<Object> valueSer, TypeSerializer typeSer)
throws IOException
{
if (value == null) {
_serializeNull(gen);
return;
}
// Let's ensure types are compatible at this point
if ((rootType != null) && !rootType.getRawClass().isAssignableFrom(value.getClass())) {
_reportIncompatibleRootType(value, rootType);
}
/* 12-Jun-2015, tatu: nominal root type is necessary for Maps at least;
* possibly collections, but can cause problems for other polymorphic
* types. We really need to distinguish between serialization type,
* base type; but right we don't. Hence this check
*/
if (valueSer == null) {
if ((rootType != null) && rootType.isContainerType()) {
valueSer = findValueSerializer(rootType, null);
} else {
valueSer = findValueSerializer(value.getClass(), null);
}
}
final boolean wrap;
PropertyName rootName = _config.getFullRootName();
if (rootName == null) {
wrap = _config.isEnabled(SerializationFeature.WRAP_ROOT_VALUE);
if (wrap) {
gen.writeStartObject();
PropertyName pname = _config.findRootName(value.getClass());
gen.writeFieldName(pname.simpleAsEncoded(_config));
}
} else if (rootName.isEmpty()) {
wrap = false;
} else {
wrap = true;
gen.writeStartObject();
gen.writeFieldName(rootName.getSimpleName());
}
try {
valueSer.serializeWithType(value, gen, this, typeSer);
if (wrap) {
gen.writeEndObject();
}
} catch (IOException ioe) { // no wrapping for IO (and derived)
throw ioe;
} catch (Exception e) { // but others do need to be, to get path etc
String msg = e.getMessage();
if (msg == null) {
msg = "[no message for "+e.getClass().getName()+"]";
}
throw new JsonMappingException(msg, e);
}
}
/**
* @deprecated since 2.6; remove from 2.7 or later
*/
@Deprecated
public void serializePolymorphic(JsonGenerator gen, Object value, TypeSerializer typeSer)
throws IOException
{
JavaType t = (value == null) ? null : _config.constructType(value.getClass());
serializePolymorphic(gen, value, t, null, typeSer);
}
/**
* Helper method called when root value to serialize is null
*
* @since 2.3
*/
protected void _serializeNull(JsonGenerator gen) throws IOException
{
JsonSerializer<Object> ser = getDefaultNullValueSerializer();
try {
ser.serialize(null, gen, this);
} catch (IOException ioe) { // no wrapping for IO (and derived)
throw ioe;
} catch (Exception e) { // but others do need to be, to get path etc
String msg = e.getMessage();
if (msg == null) {
msg = "[no message for "+e.getClass().getName()+"]";
}
throw new JsonMappingException(msg, e);
}
}
/**
* The method to be called by {@link ObjectMapper
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
/**
* Standard deserializer for {@link EnumSet}s.
* <p>
* Note: casting within this class is all messed up -- just could not figure out a way
* to properly deal with recursive definition of "EnumSet<K extends Enum<K>, V>
*/
@SuppressWarnings("rawtypes")
public class EnumSetDeserializer
extends StdDeserializer<EnumSet<?>>
implements ContextualDeserializer
{
private static final long serialVersionUID = 1L; // since 2.5
protected final JavaType _enumType;
protected final Class<Enum> _enumClass;
protected JsonDeserializer<Enum<?>> _enumDeserializer;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
@SuppressWarnings("unchecked" )
public EnumSetDeserializer(JavaType enumType, JsonDeserializer<?> deser)
{
super(EnumSet.class);
_enumType = enumType;
_enumClass = (Class<Enum>) enumType.getRawClass();
// sanity check
if (!_enumClass.isEnum()) {
throw new IllegalArgumentException("Type "+enumType+" not Java Enum type");
}
_enumDeserializer = (JsonDeserializer<Enum<?>>) deser;
}
public EnumSetDeserializer withDeserializer(JsonDeserializer<?> deser) {
if (_enumDeserializer == deser) {
return this;
}
return new EnumSetDeserializer(_enumType, deser);
}
/**
* Because of costs associated with constructing Enum resolvers,
* let's cache instances by default.
*/
@Override
public boolean isCachable() {
// One caveat: content deserializer should prevent caching
if (_enumType.getValueHandler() != null) {
return false;
}
return true;
}
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
JsonDeserializer<?> deser = _enumDeserializer;
if (deser == null) {
deser = ctxt.findContextualValueDeserializer(_enumType, property);
} else { // if directly assigned, probably not yet contextual, so:
deser = ctxt.handleSecondaryContextualization(deser, property, _enumType);
}
return withDeserializer(deser);
}
/*
/**********************************************************
/* JsonDeserializer API
/**********************************************************
*/
@SuppressWarnings("unchecked")
@Override
public EnumSet<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// Ok: must point to START_ARRAY (or equivalent)
if (!jp.isExpectedStartArrayToken()) {
throw ctxt.mappingException(EnumSet.class);
}
EnumSet result = constructSet();
JsonToken t;
try {
while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
/* What to do with nulls? Fail or ignore? Fail, for now
* (note: would fail if we passed it to EnumDeserializer, too,
* but in general nulls should never be passed to non-container
* deserializers)
*/
if (t == JsonToken.
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> beanDesc, TypeSerializer typeSer)
{
/* 16-Aug-2010, tatu: If there is a (value) type serializer, we can not force
* static typing; that would make it impossible to handle expected subtypes
*/
if (typeSer != null) {
return false;
}
AnnotationIntrospector intr = config.getAnnotationIntrospector();
JsonSerialize.Typing t = intr.findSerializationTyping(beanDesc.getClassInfo());
if (t != null && t != JsonSerialize.Typing.DEFAULT_TYPING) {
return (t == JsonSerialize.Typing.STATIC);
}
return config.isEnabled(MapperFeature.USE_STATIC_TYPING);
}
protected Class<?> _verifyAsClass(Object src, String methodName, Class<?> noneClass)
{
if (src == null) {
return null;
}
if (!(src instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector."+methodName+"() returned value of type "+src.getClass().getName()+": expected type JsonSerializer or Class<JsonSerializer> instead");
}
Class<?> cls = (Class<?>) src;
if (cls == noneClass || ClassUtil.isBogusClass(cls)) {
return null;
}
return cls;
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>One, int typeIndex, boolean explicit)
{
final int mask = (1 << typeIndex);
_hasNonDefaultCreator = true;
AnnotatedWithParams oldOne = _creators[typeIndex];
// already had an explicitly marked one?
if (oldOne != null) {
boolean verify;
if ((_explicitCreators & mask) != 0) { // already had explicitly annotated, leave as-is
// but skip, if new one not annotated
if (!explicit) {
return;
}
// both explicit: verify
verify = true;
} else {
// otherwise only verify if neither explicitly annotated.
verify = !explicit;
}
// one more thing: ok to override in sub-class
if (verify && (oldOne.getClass() == newOne.getClass())) {
// [databind#667]: avoid one particular class of bogus problems
Class<?> oldType = oldOne.getRawParameterType(0);
Class<?> newType = newOne.getRawParameterType(0);
if (oldType == newType) {
throw new IllegalArgumentException("Conflicting "+TYPE_DESCS[typeIndex]
+" creators: already had explicitly marked "+oldOne+", encountered "+newOne);
}
// otherwise, which one to choose?
if (newType.isAssignableFrom(oldType)) {
// new type more generic, use old
return;
}
// new type more specific, use it
}
}
if (explicit) {
_explicitCreators |= mask;
}
_creators[typeIndex] = _fixAccess(newOne);
}
/*
/**********************************************************
/* Helper class(es)
/**********************************************************
*/
protected final static class Vanilla
extends ValueInstantiator
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
public final static int TYPE_COLLECTION = 1;
public final static int TYPE_MAP = 2;
public final static int TYPE_HASH_MAP = 3;
private final int _type;
public Vanilla(int t) {
_type = t;
}
@Override
public String getValueTypeDesc() {
switch (_type) {
case TYPE_COLLECTION: return ArrayList.class.getName();
case TYPE_MAP: return LinkedHashMap.class.getName();
case TYPE_HASH_MAP: return HashMap.class.getName();
}
return Object.class.getName();
}
@Override
public boolean canInstantiate() { return true; }
@Override
public boolean canCreateUsingDefault() { return true; }
@Override
public Object createUsingDefault(DeserializationContext ctxt) throws IOException {
switch (_type) {
case TYPE_COLLECTION: return new ArrayList<Object>();
case TYPE_MAP: return new LinkedHashMap<String,Object>();
case TYPE_HASH_MAP: return new HashMap<String,Object>();
}
throw new IllegalStateException("Unknown type "+_type);
}
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> type = type.narrowContentsBy(cc);
} catch (IllegalArgumentException iae) {
throw new JsonMappingException("Failed to narrow content type "+type+" with content-type annotation ("+cc.getName()+"): "+iae.getMessage(), null, iae);
}
}
// ... as well as deserializer for contents:
JavaType contentType = type.getContentType();
if (contentType.getValueHandler() == null) { // as with above, avoid resetting (which would trigger exception)
Object cdDef = intr.findContentDeserializer(a);
if (cdDef != null) {
JsonDeserializer<?> cd = null;
if (cdDef instanceof JsonDeserializer<?>) {
cdDef = (JsonDeserializer<?>) cdDef;
} else {
Class<?> cdClass = _verifyAsClass(cdDef, "findContentDeserializer", JsonDeserializer.None.class);
if (cdClass != null) {
cd = ctxt.deserializerInstance(a, cdClass);
}
}
if (cd != null) {
type = type.withContentValueHandler(cd);
}
}
}
}
return type;
}
/*
/**********************************************************
/* Helper methods, other
/**********************************************************
*/
/**
* Helper method used to prevent both caching and cache lookups for structured
* types that have custom value handlers
*
* @since 2.4.6
*/
private boolean _hasCustomValueHandler(JavaType t) {
if (t.isContainerType()) {
JavaType ct = t.getContentType();
if (ct != null) {
return (ct.getValueHandler() != null) || (ct.getTypeHandler() != null);
}
}
return false;
}
private Class<?> _verifyAsClass(Object src, String methodName, Class<?> noneClass)
{
if (src == null) {
return null;
}
if (!(src instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector."+methodName+"() returned value of type "+src.getClass().getName()+": expected type JsonSerializer or Class<JsonSerializer> instead");
}
Class<?> cls = (Class<?>) src;
if (cls == noneClass || ClassUtil.isBogusClass(cls)) {
return null;
}
return cls;
}
/*
/**********************************************************
/* Overridable error reporting methods
/**********************************************************
*/
protected JsonDeserializer<Object> _handleUnknownValueDeserializer(JavaType type)
throws JsonMappingException
{
/* Let's try to figure out the reason, to give better error
* messages
*/
Class<?> rawClass = type.getRawClass();
if (!ClassUtil.isConcrete(rawClass)) {
throw new JsonMappingException("Can not find a Value deserializer for abstract type "+type);
}
throw new JsonMappingException("Can not find a Value deserializer for type "+type);
}
protected KeyDeserializer _handleUnknownKeyDeserializer(JavaType type)
throws JsonMappingException
{
throw new JsonMappingException("Can not find a (Map) Key deserializer for type "+type);
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.util.Arrays;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Value node that contains Base64 encoded binary value, which will be
* output and stored as Json String value.
*/
public class BinaryNode
extends ValueNode
{
final static BinaryNode EMPTY_BINARY_NODE = new BinaryNode(new byte[0]);
protected final byte[] _data;
public BinaryNode(byte[] data)
{
_data = data;
}
public BinaryNode(byte[] data, int offset, int length)
{
if (offset == 0 && length == data.length) {
_data = data;
} else {
_data = new byte[length];
System.arraycopy(data, offset, _data, 0, length);
}
}
public static BinaryNode valueOf(byte[] data)
{
if (data == null) {
return null;
}
if (data.length == 0) {
return EMPTY_BINARY_NODE;
}
return new BinaryNode(data);
}
public static BinaryNode valueOf(byte[] data, int offset, int length)
{
if (data == null) {
return null;
}
if (length == 0) {
return EMPTY_BINARY_NODE;
}
return new BinaryNode(data, offset, length);
}
@Override
public JsonNodeType getNodeType()
{
return JsonNodeType.BINARY;
}
@Override
public JsonToken asToken() {
/* No distinct type; could use one for textual values,
* but given that it's not in text form at this point,
* embedded-object is closest
*/
return JsonToken.VALUE_EMBEDDED_OBJECT;
}
/**
*<p>
* Note: caller is not to modify returned array in any way, since
* it is not a copy but reference to the underlying byte array.
*/
@Override
public byte[] binaryValue() { return _data; }
/**
* Hmmh. This is not quite as efficient as using {@link #serialize},
* but will work correctly.
*/
@Override
public String asText() {
return Base64Variants.getDefaultVariant().encode(_data, false);
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.writeBinary(provider.getConfig().getBase64Variant(),
_data, 0, _data.length);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (!(o instanceof BinaryNode)) {
return false;
}
return Arrays.equals(((BinaryNode) o)._data, _data);
}
@Override
public int hashCode() {
return (_data == null) ? -1 : _data.length;
}
/**
* Different from other values, since contents need to be surrounded
* by (double) quotes.
*/
@Override
public String toString()
{
return Base64Variants.getDefaultVariant().encode(_data, true);
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>);
}
protected boolean isDefaultKeyDeserializer(KeyDeserializer keyDeser) {
return ClassUtil.isJacksonStdImpl(keyDeser);
}
/*
/**********************************************************
/* Partial JsonDeserializer implementation
/**********************************************************
*/
/**
* Base implementation that does not assume specific type
* inclusion mechanism. Sub-classes are expected to override
* this method if they are to handle type information.
*/
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException {
return typeDeserializer.deserializeTypedFromAny(jp, ctxt);
}
/*
/**********************************************************
/* Helper methods for sub-classes, parsing: while mostly
/* useful for numeric types, can be also useful for dealing
/* with things serialized as numbers (such as Dates).
/**********************************************************
*/
protected final boolean _parseBooleanPrimitive(JsonParser jp, DeserializationContext ctxt) throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_TRUE) return true;
if (t == JsonToken.VALUE_FALSE) return false;
if (t == JsonToken.VALUE_NULL) return false;
// [JACKSON-78]: should accept ints too, (0 == false, otherwise true)
if (t == JsonToken.VALUE_NUMBER_INT) {
// 11-Jan-2012, tatus: May be outside of int...
if (jp.getNumberType() == NumberType.INT) {
return (jp.getIntValue() != 0);
}
return _parseBooleanFromNumber(jp, ctxt);
}
// And finally, let's allow Strings to be converted too
if (t == JsonToken.VALUE_STRING) {
String text = jp.getText().trim();
// [#422]: Allow aliases
if ("true".equals(text) || "True".equals(text)) {
return true;
}
if ("false".equals(text) || "False".equals(text) || text.length() == 0) {
return false;
}
if (_hasTextualNull(text)) {
return false;
}
throw ctxt.weirdStringException(text, _valueClass, "only \"true\" or \"false\" recognized");
}
// [databind#381]
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final boolean parsed = _parseBooleanPrimitive(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'boolean' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final Boolean _parseBoolean(JsonParser p, DeserializationContext ctxt)
throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_TRUE) {
return Boolean.TRUE;
}
if (t == JsonToken.VALUE_FALSE) {
return Boolean.FALSE;
}
// [JACKSON-78]: should accept ints too, (0 == false, otherwise true)
if
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> (t == JsonToken.VALUE_NUMBER_INT) {
// 11-Jan-2012, tatus: May be outside of int...
if (p.getNumberType() == NumberType.INT) {
return (p.getIntValue() == 0) ? Boolean.FALSE : Boolean.TRUE;
}
return Boolean.valueOf(_parseBooleanFromNumber(p, ctxt));
}
if (t == JsonToken.VALUE_NULL) {
return (Boolean) getNullValue(ctxt);
}
// And finally, let's allow Strings to be converted too
if (t == JsonToken.VALUE_STRING) {
String text = p.getText().trim();
// [#422]: Allow aliases
if ("true".equals(text) || "True".equals(text)) {
return Boolean.TRUE;
}
if ("false".equals(text) || "False".equals(text)) {
return Boolean.FALSE;
}
if (text.length() == 0) {
return (Boolean) getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return (Boolean) getNullValue(ctxt);
}
throw ctxt.weirdStringException(text, _valueClass, "only \"true\" or \"false\" recognized");
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Boolean parsed = _parseBoolean(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Boolean' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final boolean _parseBooleanFromNumber(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
if (jp.getNumberType() == NumberType.LONG) {
return (jp.getLongValue() == 0L) ? Boolean.FALSE : Boolean.TRUE;
}
// no really good logic; let's actually resort to textual comparison
String str = jp.getText();
if ("0.0".equals(str) || "0".equals(str)) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}
protected Byte _parseByte(JsonParser p, DeserializationContext ctxt)
throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT) {
return p.getByteValue();
}
if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
String text = p.getText().trim();
if (_hasTextualNull(text)) {
return (Byte) getNullValue(ctxt);
}
int value;
try {
int len = text.length();
if (len == 0) {
return (Byte) getEmptyValue(ctxt);
}
value = NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid Byte value");
}
// So far so good: but does it fit?
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> // as per [JACKSON-804], allow range up to 255, inclusive
if (value < Byte.MIN_VALUE || value > 255) {
throw ctxt.weirdStringException(text, _valueClass, "overflow, value can not be represented as 8-bit value");
}
return Byte.valueOf((byte) value);
}
if (t == JsonToken.VALUE_NUMBER_FLOAT) {
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Byte");
}
return p.getByteValue();
}
if (t == JsonToken.VALUE_NULL) {
return (Byte) getNullValue(ctxt);
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Byte parsed = _parseByte(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Byte' value but there was more than a single value in the array");
}
return parsed;
}
throw ctxt.mappingException(_valueClass, t);
}
protected Short _parseShort(JsonParser p, DeserializationContext ctxt)
throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT) {
return p.getShortValue();
}
if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
String text = p.getText().trim();
int value;
try {
int len = text.length();
if (len == 0) {
return (Short) getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return (Short) getNullValue(ctxt);
}
value = NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid Short value");
}
// So far so good: but does it fit?
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
throw ctxt.weirdStringException(text, _valueClass, "overflow, value can not be represented as 16-bit value");
}
return Short.valueOf((short) value);
}
if (t == JsonToken.VALUE_NUMBER_FLOAT) {
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Short");
}
return p.getShortValue();
}
if (t == JsonToken.VALUE_NULL) {
return (Short) getNullValue(ctxt);
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Short parsed = _parseShort(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> to unwrap single value array for single 'Short' value but there was more than a single value in the array");
}
return parsed;
}
throw ctxt.mappingException(_valueClass, t);
}
protected final short _parseShortPrimitive(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
int value = _parseIntPrimitive(jp, ctxt);
// So far so good: but does it fit?
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
throw ctxt.weirdStringException(String.valueOf(value),
_valueClass, "overflow, value can not be represented as 16-bit value");
}
return (short) value;
}
protected final int _parseIntPrimitive(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (p.hasToken(JsonToken.VALUE_NUMBER_INT)) {
return p.getIntValue();
}
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
String text = p.getText().trim();
if (_hasTextualNull(text)) {
return 0;
}
try {
int len = text.length();
if (len > 9) {
long l = Long.parseLong(text);
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
throw ctxt.weirdStringException(text, _valueClass,
"Overflow: numeric value ("+text+") out of range of int ("+Integer.MIN_VALUE+" - "+Integer.MAX_VALUE+")");
}
return (int) l;
}
if (len == 0) {
return 0;
}
return NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid int value");
}
}
if (t == JsonToken.VALUE_NUMBER_FLOAT) {
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "int");
}
return p.getValueAsInt();
}
if (t == JsonToken.VALUE_NULL) {
return 0;
}
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final int parsed = _parseIntPrimitive(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'int' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final Integer _parseInteger(JsonParser p, DeserializationContext ctxt)
throws IOException
{
switch (p.getCurrentTokenId()) {
// NOTE: caller assumed to usually check VALUE_NUMBER_INT in fast path
case JsonTokenId.ID_NUMBER_INT:
return Integer.valueOf(p.getIntValue());
case JsonTokenId.ID_NUMBER_FLOAT: // coercing may work too
if (!ctxt.isEnabled(DeserializationFeature.
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Integer");
}
return Integer.valueOf(p.getValueAsInt());
case JsonTokenId.ID_STRING: // let's do implicit re-parse
String text = p.getText().trim();
try {
int len = text.length();
if (_hasTextualNull(text)) {
return (Integer) getNullValue(ctxt);
}
if (len > 9) {
long l = Long.parseLong(text);
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
throw ctxt.weirdStringException(text, _valueClass,
"Overflow: numeric value ("+text+") out of range of Integer ("+Integer.MIN_VALUE+" - "+Integer.MAX_VALUE+")");
}
return Integer.valueOf((int) l);
}
if (len == 0) {
return (Integer) getEmptyValue(ctxt);
}
return Integer.valueOf(NumberInput.parseInt(text));
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid Integer value");
}
case JsonTokenId.ID_NULL:
return (Integer) getNullValue(ctxt);
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Integer parsed = _parseInteger(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Integer' value but there was more than a single value in the array");
}
return parsed;
}
break;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
protected final Long _parseLong(JsonParser p, DeserializationContext ctxt) throws IOException
{
switch (p.getCurrentTokenId()) {
// NOTE: caller assumed to usually check VALUE_NUMBER_INT in fast path
case JsonTokenId.ID_NUMBER_INT:
return p.getLongValue();
case JsonTokenId.ID_NUMBER_FLOAT:
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Long");
}
return p.getValueAsLong();
case JsonTokenId.ID_STRING:
// let's allow Strings to be converted too
// !!! 05-Jan-2009, tatu: Should we try to limit value space, JDK is too lenient?
String text = p.getText().trim();
if (text.length() == 0) {
return (Long) getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return (Long) getNullValue(ctxt);
}
try {
return Long.valueOf(NumberInput.parseLong(text));
} catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid Long value");
case JsonTokenId.ID_NULL:
return (Long) getNullValue(ctxt);
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Long parsed = _parseLong(p, ctxt);
JsonToken t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Long' value but there was more than a single value in the array");
}
return parsed;
}
break;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
protected final long _parseLongPrimitive(JsonParser p, DeserializationContext ctxt)
throws IOException
{
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_NUMBER_INT:
return p.getLongValue();
case JsonTokenId.ID_NUMBER_FLOAT:
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "long");
}
return p.getValueAsLong();
case JsonTokenId.ID_STRING:
String text = p.getText().trim();
if (text.length() == 0 || _hasTextualNull(text)) {
return 0L;
}
try {
return NumberInput.parseLong(text);
} catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid long value");
case JsonTokenId.ID_NULL:
return 0L;
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final long parsed = _parseLongPrimitive(p, ctxt);
JsonToken t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'long' value but there was more than a single value in the array");
}
return parsed;
}
break;
}
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
protected final Float _parseFloat(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
// We accept couple of different types; obvious ones first:
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too
return jp.getFloatValue();
}
// And finally, let's allow Strings to be converted too
if (t == JsonToken.VALUE_STRING) {
String text = jp.getText().trim();
if (text.length() == 0) {
return (Float) getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return (Float) getNullValue(ctxt);
}
switch (text.charAt(0)) {
case 'I':
if (_isPosInf(text)) {
return Float.POSITIVE_INFINITY;
}
break;
case 'N':
if (_isNaN(text)) {
return Float.NaN;
}
break;
case '-':
if (_isNegInf(text)) {
return Float.NEGATIVE_INFINITY;
}
break;
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>
try {
return Float.parseFloat(text);
} catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid Float value");
}
if (t == JsonToken.VALUE_NULL) {
return (Float) getNullValue(ctxt);
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final Float parsed = _parseFloat(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Byte' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final float _parseFloatPrimitive(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too
return jp.getFloatValue();
}
if (t == JsonToken.VALUE_STRING) {
String text = jp.getText().trim();
if (text.length() == 0 || _hasTextualNull(text)) {
return 0.0f;
}
switch (text.charAt(0)) {
case 'I':
if (_isPosInf(text)) {
return Float.POSITIVE_INFINITY;
}
break;
case 'N':
if (_isNaN(text)) { return Float.NaN; }
break;
case '-':
if (_isNegInf(text)) {
return Float.NEGATIVE_INFINITY;
}
break;
}
try {
return Float.parseFloat(text);
} catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid float value");
}
if (t == JsonToken.VALUE_NULL) {
return 0.0f;
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final float parsed = _parseFloatPrimitive(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'float' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final Double _parseDouble(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too
return jp.getDoubleValue();
}
if (t == JsonToken.VALUE_STRING) {
String text = jp.getText().trim();
if (text.length() == 0) {
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> return (Double) getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return (Double) getNullValue(ctxt);
}
switch (text.charAt(0)) {
case 'I':
if (_isPosInf(text)) {
return Double.POSITIVE_INFINITY;
}
break;
case 'N':
if (_isNaN(text)) {
return Double.NaN;
}
break;
case '-':
if (_isNegInf(text)) {
return Double.NEGATIVE_INFINITY;
}
break;
}
try {
return parseDouble(text);
} catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid Double value");
}
if (t == JsonToken.VALUE_NULL) {
return (Double) getNullValue(ctxt);
}
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final Double parsed = _parseDouble(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Double' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final double _parseDoublePrimitive(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
// We accept couple of different types; obvious ones first:
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too
return jp.getDoubleValue();
}
// And finally, let's allow Strings to be converted too
if (t == JsonToken.VALUE_STRING) {
String text = jp.getText().trim();
if (text.length() == 0 || _hasTextualNull(text)) {
return 0.0;
}
switch (text.charAt(0)) {
case 'I':
if (_isPosInf(text)) {
return Double.POSITIVE_INFINITY;
}
break;
case 'N':
if (_isNaN(text)) {
return Double.NaN;
}
break;
case '-':
if (_isNegInf(text)) {
return Double.NEGATIVE_INFINITY;
}
break;
}
try {
return parseDouble(text);
} catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid double value");
}
if (t == JsonToken.VALUE_NULL) {
return 0.0;
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final double parsed = _parseDoublePrimitive(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Byte' value but there was more than a single value in the
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected java.util.Date _parseDate(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT) {
return new java.util.Date(jp.getLongValue());
}
if (t == JsonToken.VALUE_NULL) {
return (java.util.Date) getNullValue(ctxt);
}
if (t == JsonToken.VALUE_STRING) {
String value = null;
try {
// As per [JACKSON-203], take empty Strings to mean
value = jp.getText().trim();
if (value.length() == 0) {
return (Date) getEmptyValue(ctxt);
}
if (_hasTextualNull(value)) {
return (java.util.Date) getNullValue(ctxt);
}
return ctxt.parseDate(value);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(value, _valueClass,
"not a valid representation (error: "+iae.getMessage()+")");
}
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final Date parsed = _parseDate(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'java.util.Date' value but there was more than a single value in the array");
}
return parsed;
}
throw ctxt.mappingException(_valueClass, t);
}
/**
* Helper method for encapsulating calls to low-level double value parsing; single place
* just because we need a work-around that must be applied to all calls.
*/
protected final static double parseDouble(String numStr) throws NumberFormatException
{
// [JACKSON-486]: avoid some nasty float representations... but should it be MIN_NORMAL or MIN_VALUE?
// for now, MIN_VALUE, since MIN_NORMAL is JDK 1.6
if (NumberInput.NASTY_SMALL_DOUBLE.equals(numStr)) {
return Double.MIN_VALUE;
}
return Double.parseDouble(numStr);
}
/**
* Helper method used for accessing String value, if possible, doing
* necessary conversion or throwing exception as necessary.
*
* @since 2.1
*/
protected final String _parseString(JsonParser jp, DeserializationContext ctxt) throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_STRING) {
return jp.getText();
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final String parsed = _parseString(jp, ctxt);
if (jp.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> single 'String' value but there was more than a single value in the array");
}
return parsed;
}
String value = jp.getValueAsString();
if (value != null) {
return value;
}
throw ctxt.mappingException(String.class, jp.getCurrentToken());
}
/**
* Helper method that may be used to support fallback for Empty String / Empty Array
* non-standard representations; usually for things serialized as JSON Objects.
*
* @since 2.5
*/
protected T _deserializeFromEmpty(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.START_ARRAY) {
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT)) {
t = jp.nextToken();
if (t == JsonToken.END_ARRAY) {
return null;
}
throw ctxt.mappingException(handledType(), JsonToken.START_ARRAY);
}
} else if (t == JsonToken.VALUE_STRING) {
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
String str = jp.getText().trim();
if (str.isEmpty()) {
return null;
}
}
}
throw ctxt.mappingException(handledType());
}
/**
* Helper method called to determine if we are seeing String value of
* "null", and, further, that it should be coerced to null just like
* null token.
*
* @since 2.3
*/
protected boolean _hasTextualNull(String value) {
return "null".equals(value);
}
protected final boolean _isNegInf(String text) {
return "-Infinity".equals(text) || "-INF".equals(text);
}
protected final boolean _isPosInf(String text) {
return "Infinity".equals(text) || "INF".equals(text);
}
protected final boolean _isNaN(String text) { return "NaN".equals(text); }
/*
/****************************************************
/* Helper methods for sub-classes, coercions
/****************************************************
*/
/**
* Helper method called in case where an integral number is encountered, but
* config settings suggest that a coercion may be needed to "upgrade"
* {@link java.lang.Number} into "bigger" type like {@link java.lang.Long} or
* {@link java.math.BigInteger}
*
* @see DeserializationFeature#USE_BIG_INTEGER_FOR_INTS
* @see DeserializationFeature#USE_LONG_FOR_INTS
*
* @since 2.6
*/
protected Object _coerceIntegral(JsonParser p, DeserializationContext ctxt) throws IOException
{
int feats = ctxt.getDeserializationFeatures();
if (DeserializationFeature.USE_BIG_INTEGER_FOR_INTS.enabledIn(feats)) {
return p.getBigIntegerValue();
}
if (DeserializationFeature.USE_LONG_FOR_INTS.enabledIn(feats)) {
return p.getLongValue();
}
return p.getBigIntegerValue(); // should be optimal, whatever it is
}
/*
/****************************************************
/* Helper methods for sub-classes, resolving dependencies
/****************************************************
*/
/**
* Helper method used to locate deserializers for properties the
* type this deserializer handles
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.ObjectBuffer;
/**
* Separate implementation for serializing String arrays (instead of
* using {@link ObjectArrayDeserializer}.
* Used if (and only if) no custom value deserializers are used.
*/
@JacksonStdImpl
public final class StringArrayDeserializer
extends StdDeserializer<String[]>
implements ContextualDeserializer
{
private static final long serialVersionUID = 1L;
public final static StringArrayDeserializer instance = new StringArrayDeserializer();
/**
* Value serializer to use, if not the standard one (which is inlined)
*/
protected JsonDeserializer<String> _elementDeserializer;
public StringArrayDeserializer() {
super(String[].class);
_elementDeserializer = null;
}
@SuppressWarnings("unchecked")
protected StringArrayDeserializer(JsonDeserializer<?> deser) {
super(String[].class);
_elementDeserializer = (JsonDeserializer<String>) deser;
}
@Override
public String[] deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// Ok: must point to START_ARRAY (or equivalent)
if (!jp.isExpectedStartArrayToken()) {
return handleNonArray(jp, ctxt);
}
if (_elementDeserializer != null) {
return _deserializeCustom(jp, ctxt);
}
final ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] chunk = buffer.resetAndStart();
int ix = 0;
try {
while (true) {
String value = jp.nextTextValue();
if (value == null) {
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.END_ARRAY) {
break;
}
if (t != JsonToken.VALUE_NULL) {
value = _parseString(jp, ctxt);
}
}
if (ix >= chunk.length) {
chunk = buffer.appendCompletedChunk(chunk);
ix = 0;
}
chunk[ix++] = value;
}
} catch (Exception e) {
throw JsonMappingException.wrapWithPath(e, chunk, buffer.bufferedSize() + ix);
}
String[] result = buffer.completeAndClearBuffer(chunk, ix, String.class);
ctxt.returnObjectBuffer(buffer);
return result;
}
/**
* Offlined version used when we do not use the default deserialization method.
*/
protected final String[] _deserializeCustom(JsonParser jp, DeserializationContext ctxt) throws IOException
{
final ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] chunk = buffer.resetAndStart();
final JsonDeserializer<String> deser = _elementDeserializer;
int ix = 0;
try {
while (true) {
/* 30-Dec-2014, tatu: This may look odd, but let's actually call method
* that suggest we are expecting a String; this helps with some formats,
* notably XML. Note, however, that while we can get String, we can't
* assume
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> that's what we use due to custom deserializer
*/
String value;
if (jp.nextTextValue() == null) {
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.END_ARRAY) {
break;
}
// Ok: no need to convert Strings, but must recognize nulls
value = (t == JsonToken.VALUE_NULL) ? deser.getNullValue(ctxt) : deser.deserialize(jp, ctxt);
} else {
value = deser.deserialize(jp, ctxt);
}
if (ix >= chunk.length) {
chunk = buffer.appendCompletedChunk(chunk);
ix = 0;
}
chunk[ix++] = value;
}
} catch (Exception e) {
// note: pass String.class, not String[].class, as we need element type for error info
throw JsonMappingException.wrapWithPath(e, String.class, ix);
}
String[] result = buffer.completeAndClearBuffer(chunk, ix, String.class);
ctxt.returnObjectBuffer(buffer);
return result;
}
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException {
return typeDeserializer.deserializeTypedFromArray(jp, ctxt);
}
private final String[] handleNonArray(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// [JACKSON-526]: implicit arrays from single values?
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)) {
// [JACKSON-620] Empty String can become null...
if ((jp.getCurrentToken() == JsonToken.VALUE_STRING)
&& ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
String str = jp.getText();
if (str.length() == 0) {
return null;
}
}
throw ctxt.mappingException(_valueClass);
}
return new String[] { (jp.getCurrentToken() == JsonToken.VALUE_NULL) ? null : _parseString(jp, ctxt) };
}
/**
* Contextualization is needed to see whether we can "inline" deserialization
* of String values, or if we have to use separate value deserializer.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException
{
JsonDeserializer<?> deser = _elementDeserializer;
// #125: May have a content converter
deser = findConvertingContentDeserializer(ctxt, property, deser);
JavaType type = ctxt.constructType(String.class);
if (deser == null) {
deser = ctxt.findContextualValueDeserializer(type, property);
} else { // if directly assigned, probably not yet contextual, so:
deser = ctxt.handleSecondaryContextualization(deser, property, type);
}
// Ok ok: if all we got is the default String deserializer, can just forget about it
if (deser != null && this.isDefaultDeserializer(deser)) {
deser = null;
}
if (_elementDeserializer != deser) {
return new StringArrayDeserializer(deser);
}
return this;
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>Type t = _bindings.get(name);
if (t != null) {
return t;
}
if (_placeholders != null && _placeholders.contains(name)) {
return UNBOUND;
}
if (_parentBindings != null) {
return _parentBindings.findType(name);
}
// nothing found, so...
// Should we throw an exception or just return null?
/* [JACKSON-499] 18-Feb-2011, tatu: There are some tricky type bindings within
* java.util, such as HashMap$KeySet; so let's punt the problem
* (honestly not sure what to do -- they are unbound for good, I think)
*/
if (_contextClass != null) {
Class<?> enclosing = _contextClass.getEnclosingClass();
if (enclosing != null) {
// [JACKSON-572]: Actually, let's skip this for all non-static inner classes
// (which will also cover 'java.util' type cases...
if (!Modifier.isStatic(_contextClass.getModifiers())) {
return UNBOUND;
}
// ... so this piece of code should not be needed any more
/*
Package pkg = enclosing.getPackage();
if (pkg != null) {
// as per [JACKSON-533], also include "java.util.concurrent":
if (pkg.getName().startsWith("java.util")) {
return UNBOUND;
}
}
*/
}
}
if (!mustFind) {
return null;
}
String className;
if (_contextClass != null) {
className = _contextClass.getName();
} else if (_contextType != null) {
className = _contextType.toString();
} else {
className = "UNKNOWN";
}
throw new IllegalArgumentException("Type variable '"+name
+"' can not be resolved (with context of class "+className+")");
//t = UNBOUND;
}
public void addBinding(String name, JavaType type)
{
// note: emptyMap() is unmodifiable, hence second check is needed:
if (_bindings == null || _bindings.size() == 0) {
_bindings = new LinkedHashMap<String,JavaType>();
}
_bindings.put(name, type);
}
public JavaType[] typesAsArray()
{
if (_bindings == null) {
_resolve();
}
if (_bindings.size() == 0) {
return NO_TYPES;
}
return _bindings.values().toArray(new JavaType[_bindings.size()]);
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected void _resolve()
{
_resolveBindings(_contextClass);
// finally: may have root level type info too
if (_contextType != null) {
int count = _contextType.containedTypeCount();
if (count > 0) {
for (int i = 0; i < count; ++i) {
String name = _contextType.containedTypeName(i);
JavaType type = _contextType.containedType(i);
addBinding(name, type);
}
}
}
// nothing bound? mark with empty map to prevent further calls
if (_bindings == null) {
_bindings = Collections.emptyMap();
}
}
public void _addPlaceholder(String name)
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> {
if (_placeholders == null) {
_placeholders = new HashSet<String>();
}
_placeholders.add(name);
}
protected void _resolveBindings(Type t)
{
if (t == null) return;
Class<?> raw;
if (t instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) t;
Type[] args = pt.getActualTypeArguments();
if (args != null && args.length > 0) {
Class<?> rawType = (Class<?>) pt.getRawType();
TypeVariable<?>[] vars = rawType.getTypeParameters();
if (vars.length != args.length) {
throw new IllegalArgumentException("Strange parametrized type (in class "+rawType.getName()+"): number of type arguments != number of type parameters ("+args.length+" vs "+vars.length+")");
}
for (int i = 0, len = args.length; i < len; ++i) {
TypeVariable<?> var = vars[i];
String name = var.getName();
if (_bindings == null) {
_bindings = new LinkedHashMap<String,JavaType>();
} else {
/* 24-Mar-2010, tatu: Better ensure that we do not overwrite something
* collected earlier (since we descend towards super-classes):
*/
if (_bindings.containsKey(name)) continue;
}
// first: add a placeholder to prevent infinite loops
_addPlaceholder(name);
// then resolve type
_bindings.put(name, _typeFactory._constructType(args[i], this));
}
}
raw = (Class<?>)pt.getRawType();
} else if (t instanceof Class<?>) {
raw = (Class<?>) t;
/* [JACKSON-677]: If this is an inner class then the generics are defined on the
* enclosing class so we have to check there as well. We don't
* need to call getEnclosingClass since anonymous classes declare
* generics
*/
Class<?> decl = raw.getDeclaringClass();
/* 08-Feb-2013, tatu: Except that if context is also super-class, we must
* skip it; context will be checked anyway, and we'd get StackOverflow if
* we went there.
*/
if (decl != null && !decl.isAssignableFrom(raw)) {
_resolveBindings(raw.getDeclaringClass());
}
/* 24-Mar-2010, tatu: Can not have true generics definitions, but can
* have lower bounds ("<T extends BeanBase>") in declaration itself
*/
TypeVariable<?>[] vars = raw.getTypeParameters();
if (vars != null && vars.length > 0) {
JavaType[] typeParams = null;
if (_contextType != null && raw.isAssignableFrom(_contextType.getRawClass())) {
typeParams = _typeFactory.findTypeParameters(_contextType, raw);
}
for (int i = 0; i < vars.length; i++) {
TypeVariable<?> var = vars[i];
String name = var.getName();
Type varType = var.getBounds()[0];
if (varType != null) {
if (_bindings == null) {
_bindings = new LinkedHashMap<String,JavaType>();
} else { // and no overwriting...
if (_bindings.containsKey(name
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* This singleton value class is used to contain explicit JSON null
* value.
*/
public final class NullNode
extends ValueNode
{
// // Just need a fly-weight singleton
public final static NullNode instance = new NullNode();
private NullNode() { }
public static NullNode getInstance() { return instance; }
@Override
public JsonNodeType getNodeType() {
return JsonNodeType.NULL;
}
@Override public JsonToken asToken() { return JsonToken.VALUE_NULL; }
@Override public String asText(String defaultValue) { return defaultValue; }
@Override public String asText() { return "null"; }
// as with MissingNode, not considered number node; hence defaults are returned if provided
/*
public int asInt(int defaultValue);
public long asLong(long defaultValue);
public double asDouble(double defaultValue);
public boolean asBoolean(boolean defaultValue);
*/
@Override
public final void serialize(JsonGenerator g, SerializerProvider provider)
throws IOException
{
provider.defaultSerializeNull(g);
}
@Override
public boolean equals(Object o) {
return (o == this);
}
@Override
public int hashCode() {
return JsonNodeType.NULL.ordinal();
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>ator.getDelegateCreator();
if (delegateCreator != null) {
JavaType delegateType = _valueInstantiator.getDelegateType(ctxt.getConfig());
delegate = findDeserializer(ctxt, delegateType, property);
}
}
JsonDeserializer<?> valueDeser = _valueDeserializer;
final JavaType valueType = _collectionType.getContentType();
if (valueDeser == null) {
// #125: May have a content converter
valueDeser = findConvertingContentDeserializer(ctxt, property, valueDeser);
if (valueDeser == null) {
// And we may also need to get deserializer for String
valueDeser = ctxt.findContextualValueDeserializer(valueType, property);
}
} else { // if directly assigned, probably not yet contextual, so:
valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, valueType);
}
if (isDefaultDeserializer(valueDeser)) {
valueDeser = null;
}
return withResolved(delegate, valueDeser);
}
/*
/**********************************************************
/* ContainerDeserializerBase API
/**********************************************************
*/
@Override
public JavaType getContentType() {
return _collectionType.getContentType();
}
@SuppressWarnings("unchecked")
@Override
public JsonDeserializer<Object> getContentDeserializer() {
JsonDeserializer<?> deser = _valueDeserializer;
return (JsonDeserializer<Object>) deser;
}
/*
/**********************************************************
/* JsonDeserializer API
/**********************************************************
*/
@SuppressWarnings("unchecked")
@Override
public Collection<String> deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
if (_delegateDeserializer != null) {
return (Collection<String>) _valueInstantiator.createUsingDelegate(ctxt,
_delegateDeserializer.deserialize(jp, ctxt));
}
final Collection<String> result = (Collection<String>) _valueInstantiator.createUsingDefault(ctxt);
return deserialize(jp, ctxt, result);
}
@Override
public Collection<String> deserialize(JsonParser jp, DeserializationContext ctxt,
Collection<String> result)
throws IOException
{
// Ok: must point to START_ARRAY
if (!jp.isExpectedStartArrayToken()) {
return handleNonArray(jp, ctxt, result);
}
if (_valueDeserializer != null) {
return deserializeUsingCustom(jp, ctxt, result, _valueDeserializer);
}
try {
while (true) {
// First the common case:
String value = jp.nextTextValue();
if (value != null) {
result.add(value);
continue;
}
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.END_ARRAY) {
break;
}
if (t != JsonToken.VALUE_NULL) {
value = _parseString(jp, ctxt);
}
result.add(value);
}
} catch (Exception e) {
throw JsonMappingException.wrapWithPath(e, result, result.size());
}
return result;
}
private Collection<String> deserializeUsingCustom(JsonParser jp, DeserializationContext ctxt,
Collection<String> result, final JsonDeserializer<String> deser) throws IOException
{
while (true) {
/* 30-Dec-2014, tatu: This may look odd, but let's actually call method
* that suggest we are expecting a String; this helps
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> with some formats,
* notably XML. Note, however, that while we can get String, we can't
* assume that's what we use due to custom deserializer
*/
String value;
if (jp.nextTextValue() == null) {
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.END_ARRAY) {
break;
}
// Ok: no need to convert Strings, but must recognize nulls
value = (t == JsonToken.VALUE_NULL) ? deser.getNullValue(ctxt) : deser.deserialize(jp, ctxt);
} else {
value = deser.deserialize(jp, ctxt);
}
result.add(value);
}
return result;
}
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException {
// In future could check current token... for now this should be enough:
return typeDeserializer.deserializeTypedFromArray(jp, ctxt);
}
/**
* Helper method called when current token is not START_ARRAY. Will either
* throw an exception, or try to handle value as if member of implicit
* array, depending on configuration.
*/
private final Collection<String> handleNonArray(JsonParser jp, DeserializationContext ctxt, Collection<String> result) throws IOException
{
// [JACKSON-526]: implicit arrays from single values?
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)) {
throw ctxt.mappingException(_collectionType.getRawClass());
}
// Strings are one of "native" (intrinsic) types, so there's never type deserializer involved
JsonDeserializer<String> valueDes = _valueDeserializer;
JsonToken t = jp.getCurrentToken();
String value;
if (t == JsonToken.VALUE_NULL) {
value = (valueDes == null) ? null : valueDes.getNullValue(ctxt);
} else {
value = (valueDes == null) ? _parseString(jp, ctxt) : valueDes.deserialize(jp, ctxt);
}
result.add(value);
return result;
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.NumberOutput;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Numeric node that contains simple 32-bit integer values.
*/
public class IntNode
extends NumericNode
{
// // // Let's cache small set of common value
final static int MIN_CANONICAL = -1;
final static int MAX_CANONICAL = 10;
private final static IntNode[] CANONICALS;
static {
int count = MAX_CANONICAL - MIN_CANONICAL + 1;
CANONICALS = new IntNode[count];
for (int i = 0; i < count; ++i) {
CANONICALS[i] = new IntNode(MIN_CANONICAL + i);
}
}
/**
* Integer value this node contains
*/
protected final int _value;
/*
************************************************
* Construction
************************************************
*/
public IntNode(int v) { _value = v; }
public static IntNode valueOf(int i) {
if (i > MAX_CANONICAL || i < MIN_CANONICAL) return new IntNode(i);
return CANONICALS[i - MIN_CANONICAL];
}
/*
/**********************************************************
/* BaseJsonNode extended API
/**********************************************************
*/
@Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_INT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.INT; }
/*
/**********************************************************
/* Overrridden JsonNode methods
/**********************************************************
*/
@Override
public boolean isIntegralNumber() { return true; }
@Override
public boolean isInt() { return true; }
@Override public boolean canConvertToInt() { return true; }
@Override public boolean canConvertToLong() { return true; }
@Override
public Number numberValue() {
return Integer.valueOf(_value);
}
@Override
public short shortValue() { return (short) _value; }
@Override
public int intValue() { return _value; }
@Override
public long longValue() { return (long) _value; }
@Override
public float floatValue() { return (float) _value; }
@Override
public double doubleValue() { return (double) _value; }
@Override
public BigDecimal decimalValue() { return BigDecimal.valueOf(_value); }
@Override
public BigInteger bigIntegerValue() { return BigInteger.valueOf(_value); }
@Override
public String asText() {
return NumberOutput.toString(_value);
}
@Override
public boolean asBoolean(boolean defaultValue) {
return _value != 0;
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.writeNumber(_value);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof IntNode) {
return ((IntNode) o)._value == _value;
}
return false;
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.NumberOutput;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Numeric node that contains simple 64-bit integer values.
*/
public class LongNode
extends NumericNode
{
protected final long _value;
/*
************************************************
* Construction
************************************************
*/
public LongNode(long v) { _value = v; }
public static LongNode valueOf(long l) { return new LongNode(l); }
/*
************************************************
* Overrridden JsonNode methods
************************************************
*/
@Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_INT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.LONG; }
@Override
public boolean isIntegralNumber() { return true; }
@Override
public boolean isLong() { return true; }
@Override public boolean canConvertToInt() {
return (_value >= Integer.MIN_VALUE && _value <= Integer.MAX_VALUE);
}
@Override public boolean canConvertToLong() { return true; }
@Override
public Number numberValue() {
return Long.valueOf(_value);
}
@Override
public short shortValue() { return (short) _value; }
@Override
public int intValue() { return (int) _value; }
@Override
public long longValue() { return _value; }
@Override
public float floatValue() { return _value; }
@Override
public double doubleValue() { return _value; }
@Override
public BigDecimal decimalValue() { return BigDecimal.valueOf(_value); }
@Override
public BigInteger bigIntegerValue() { return BigInteger.valueOf(_value); }
@Override
public String asText() {
return NumberOutput.toString(_value);
}
@Override
public boolean asBoolean(boolean defaultValue) {
return _value != 0;
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.writeNumber(_value);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof LongNode) {
return ((LongNode) o)._value == _value;
}
return false;
}
@Override
public int hashCode() {
return ((int) _value) ^ (int) (_value >> 32);
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.CharTypes;
import com.fasterxml.jackson.core.io.NumberInput;
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Value node that contains a text value.
*/
public class TextNode
extends ValueNode
{
final static TextNode EMPTY_STRING_NODE = new TextNode("");
protected final String _value;
public TextNode(String v) { _value = v; }
/**
* Factory method that should be used to construct instances.
* For some common cases, can reuse canonical instances: currently
* this is the case for empty Strings, in future possible for
* others as well. If null is passed, will return null.
*
* @return Resulting {@link TextNode} object, if <b>v</b>
* is NOT null; null if it is.
*/
public static TextNode valueOf(String v)
{
if (v == null) {
return null;
}
if (v.length() == 0) {
return EMPTY_STRING_NODE;
}
return new TextNode(v);
}
@Override
public JsonNodeType getNodeType() {
return JsonNodeType.STRING;
}
@Override public JsonToken asToken() { return JsonToken.VALUE_STRING; }
@Override
public String textValue() {
return _value;
}
/**
* Method for accessing textual contents assuming they were
* base64 encoded; if so, they are decoded and resulting binary
* data is returned.
*/
public byte[] getBinaryValue(Base64Variant b64variant) throws IOException
{
@SuppressWarnings("resource")
ByteArrayBuilder builder = new ByteArrayBuilder(100);
final String str = _value;
int ptr = 0;
int len = str.length();
main_loop:
while (ptr < len) {
// first, we'll skip preceding white space, if any
char ch;
do {
ch = str.charAt(ptr++);
if (ptr >= len) {
break main_loop;
}
} while (ch <= ' ');
int bits = b64variant.decodeBase64Char(ch);
if (bits < 0) {
_reportInvalidBase64(b64variant, ch, 0);
}
int decodedData = bits;
// then second base64 char; can't get padding yet, nor ws
if (ptr >= len) {
_reportBase64EOF();
}
ch = str.charAt(ptr++);
bits = b64variant.decodeBase64Char(ch);
if (bits < 0) {
_reportInvalidBase64(b64variant, ch, 1);
}
decodedData = (decodedData << 6) | bits;
// third base64 char; can be padding, but not ws
if (ptr >= len) {
// but as per [JACKSON-631] can be end-of-input, iff not using padding
if (!b64variant.usesPadding()) {
// Got 12 bits, only need 8, need to shift
decodedData >>= 4;
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> */
public final boolean isJavaLangObject() { return _class == Object.class; }
/**
* Accessor for checking whether handlers for dealing with values of
* this type should use static typing (as opposed to dynamic typing).
* Note that while value of 'true' does mean that static typing is to
* be used, value of 'false' may still be overridden by other settings.
*
* @since 2.2
*/
public final boolean useStaticType() { return _asStatic; }
/*
/**********************************************************
/* Public API, type parameter access; pass-through
/**********************************************************
*/
@Override
public boolean hasGenericTypes() { return containedTypeCount() > 0; }
@Override
public JavaType getKeyType() { return null; }
@Override
public JavaType getContentType() { return null; }
@Override // since 2.6
public JavaType getReferencedType() { return null; }
@Override
public int containedTypeCount() { return 0; }
@Override
public JavaType containedType(int index) { return null; }
@Override
public String containedTypeName(int index) { return null; }
@Override
public abstract Class<?> getParameterSource();
/*
/**********************************************************
/* Extended API beyond ResolvedType
/**********************************************************
*/
// NOTE: not defined in Resolved type
/**
* Convenience method that is functionally same as:
*<code>
* JavaType t = containedType(index);
* if (t == null) {
* t = TypeFactory.unknownType();
* }
*</code>
* and typically used to eliminate need for null checks for common case
* where we just want to check if containedType is available first; and
* if not, use "unknown type" (which translates to <code>java.lang.Object</code>
* basically).
*
* @since 2.5
*/
public JavaType containedTypeOrUnknown(int index) {
JavaType t = containedType(index);
return (t == null) ? TypeFactory.unknownType() : t;
}
/*
/**********************************************************
/* Semi-public API, accessing handlers
/**********************************************************
*/
/**
* Method for accessing value handler associated with this type, if any
*/
@SuppressWarnings("unchecked")
public <T> T getValueHandler() { return (T) _valueHandler; }
/**
* Method for accessing type handler associated with this type, if any
*/
@SuppressWarnings("unchecked")
public <T> T getTypeHandler() { return (T) _typeHandler; }
/**
* @since 2.6
*/
public boolean hasValueHandler() { return _valueHandler != null; }
/*
/**********************************************************
/* Support for producing signatures
/**********************************************************
*/
//public abstract String toCanonical();
/**
* Method for accessing signature that contains generic
* type information, in form compatible with JVM 1.5
* as per JLS. It is a superset of {@link #getErasedSignature},
* in that generic information can be automatically removed
* if necessary (just remove outermost
* angle brackets along with content inside)
*/
public String getGenericSignature() {
StringBuilder sb = new StringBuilder(40);
getGenericSignature(sb);
return sb.toString();
}
/**
*
* @param sb StringBuilder to append signature to
*
* @return StringBuilder
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.NumberOutput;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Numeric node that contains simple 16-bit integer values.
*/
public class ShortNode
extends NumericNode
{
protected final short _value;
/*
************************************************
* Construction
************************************************
*/
public ShortNode(short v) { _value = v; }
public static ShortNode valueOf(short l) { return new ShortNode(l); }
/*
************************************************
* Overridden JsonNode methods
************************************************
*/
@Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_INT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.INT; } // should be SHORT
@Override
public boolean isIntegralNumber() { return true; }
@Override
public boolean isShort() { return true; }
@Override public boolean canConvertToInt() { return true; }
@Override public boolean canConvertToLong() { return true; }
@Override
public Number numberValue() {
return Short.valueOf(_value);
}
@Override
public short shortValue() { return _value; }
@Override
public int intValue() { return _value; }
@Override
public long longValue() { return _value; }
@Override
public float floatValue() { return _value; }
@Override
public double doubleValue() { return _value; }
@Override
public BigDecimal decimalValue() { return BigDecimal.valueOf(_value); }
@Override
public BigInteger bigIntegerValue() { return BigInteger.valueOf(_value); }
@Override
public String asText() {
return NumberOutput.toString(_value);
}
@Override
public boolean asBoolean(boolean defaultValue) {
return _value != 0;
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.writeNumber(_value);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof ShortNode) {
return ((ShortNode) o)._value == _value;
}
return false;
}
@Override
public int hashCode() {
return _value;
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
/**
* We need a custom deserializer both because {@link ArrayBlockingQueue} has no
* default constructor AND because it has size limit used for constructing
* underlying storage automatically.
*/
public class ArrayBlockingQueueDeserializer
extends CollectionDeserializer
{
private static final long serialVersionUID = 1;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
/**
* Constructor used when creating contextualized instances.
*/
public ArrayBlockingQueueDeserializer(JavaType collectionType,
JsonDeserializer<Object> valueDeser, TypeDeserializer valueTypeDeser,
ValueInstantiator valueInstantiator,
JsonDeserializer<Object> delegateDeser)
{
super(collectionType, valueDeser, valueTypeDeser, valueInstantiator, delegateDeser);
}
/**
* Copy-constructor that can be used by sub-classes to allow
* copy-on-write styling copying of settings of an existing instance.
*/
protected ArrayBlockingQueueDeserializer(ArrayBlockingQueueDeserializer src) {
super(src);
}
/**
* Fluent-factory method call to construct contextual instance.
*/
@Override
@SuppressWarnings("unchecked")
protected ArrayBlockingQueueDeserializer withResolved(JsonDeserializer<?> dd,
JsonDeserializer<?> vd, TypeDeserializer vtd)
{
if ((dd == _delegateDeserializer) && (vd == _valueDeserializer) && (vtd == _valueTypeDeserializer)) {
return this;
}
return new ArrayBlockingQueueDeserializer(_collectionType,
(JsonDeserializer<Object>) vd, vtd,
_valueInstantiator, (JsonDeserializer<Object>) dd);
}
/*
/**********************************************************
/* JsonDeserializer API
/**********************************************************
*/
@SuppressWarnings("unchecked")
@Override
public Collection<Object> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
if (_delegateDeserializer != null) {
return (Collection<Object>) _valueInstantiator.createUsingDelegate(ctxt,
_delegateDeserializer.deserialize(jp, ctxt));
}
if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
String str = jp.getText();
if (str.length() == 0) {
return (Collection<Object>) _valueInstantiator.createFromString(ctxt, str);
}
}
return deserialize(jp, ctxt, null);
}
@Override
public Collection<Object> deserialize(JsonParser jp, DeserializationContext ctxt, Collection<Object> result0) throws IOException
{
// Ok: must point to START_ARRAY (or equivalent)
if (!jp.isExpectedStartArrayToken()) {
return handleNonArray(jp, ctxt, new ArrayBlockingQueue<Object>(1));
}
ArrayList<Object> tmp = new ArrayList<Object>();
JsonDeserializer<Object> valueDes = _valueDeserializer;
JsonToken t;
final TypeDeserializer typeDeser = _valueTypeDeserializer;
try {
while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
Object value;
if (t == JsonToken
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.base.ParserMinimalBase;
import com.fasterxml.jackson.databind.JsonNode;
/**
* Facade over {@link JsonNode} that implements {@link JsonParser} to allow
* accessing contents of JSON tree in alternate form (stream of tokens).
* Useful when a streaming source is expected by code, such as data binding
* functionality.
*/
public class TreeTraversingParser extends ParserMinimalBase
{
/*
/**********************************************************
/* Configuration
/**********************************************************
*/
protected ObjectCodec _objectCodec;
/**
* Traversal context within tree
*/
protected NodeCursor _nodeCursor;
/*
/**********************************************************
/* State
/**********************************************************
*/
/**
* Sometimes parser needs to buffer a single look-ahead token; if so,
* it'll be stored here. This is currently used for handling
*/
protected JsonToken _nextToken;
/**
* Flag needed to handle recursion into contents of child
* Array/Object nodes.
*/
protected boolean _startContainer;
/**
* Flag that indicates whether parser is closed or not. Gets
* set when parser is either closed by explicit call
* ({@link #close}) or when end-of-input is reached.
*/
protected boolean _closed;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public TreeTraversingParser(JsonNode n) { this(n, null); }
public TreeTraversingParser(JsonNode n, ObjectCodec codec)
{
super(0);
_objectCodec = codec;
if (n.isArray()) {
_nextToken = JsonToken.START_ARRAY;
_nodeCursor = new NodeCursor.ArrayCursor(n, null);
} else if (n.isObject()) {
_nextToken = JsonToken.START_OBJECT;
_nodeCursor = new NodeCursor.ObjectCursor(n, null);
} else { // value node
_nodeCursor = new NodeCursor.RootCursor(n, null);
}
}
@Override
public void setCodec(ObjectCodec c) {
_objectCodec = c;
}
@Override
public ObjectCodec getCodec() {
return _objectCodec;
}
@Override
public Version version() {
return com.fasterxml.jackson.databind.cfg.PackageVersion.VERSION;
}
/*
/**********************************************************
/* Closeable implementation
/**********************************************************
*/
@Override
public void close() throws IOException
{
if (!_closed) {
_closed = true;
_nodeCursor = null;
_currToken = null;
}
}
/*
/**********************************************************
/* Public API, traversal
/**********************************************************
*/
@Override
public JsonToken nextToken() throws IOException, JsonParseException
{
if (_nextToken != null) {
_currToken = _nextToken;
_nextToken = null;
return _currToken;
}
// are we to descend to a container child?
if (_startContainer) {
_startContainer = false;
// minor optimization: empty containers can be skipped
if (!_nodeCursor.currentHasChildren()) {
_currToken = (_currToken == JsonToken.START_OBJECT) ?
JsonToken.END_OBJECT : Json
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>Token.END_ARRAY;
return _currToken;
}
_nodeCursor = _nodeCursor.iterateChildren();
_currToken = _nodeCursor.nextToken();
if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) {
_startContainer = true;
}
return _currToken;
}
// No more content?
if (_nodeCursor == null) {
_closed = true; // if not already set
return null;
}
// Otherwise, next entry from current cursor
_currToken = _nodeCursor.nextToken();
if (_currToken != null) {
if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) {
_startContainer = true;
}
return _currToken;
}
// null means no more children; need to return end marker
_currToken = _nodeCursor.endToken();
_nodeCursor = _nodeCursor.getParent();
return _currToken;
}
// default works well here:
//public JsonToken nextValue() throws IOException, JsonParseException
@Override
public JsonParser skipChildren() throws IOException, JsonParseException
{
if (_currToken == JsonToken.START_OBJECT) {
_startContainer = false;
_currToken = JsonToken.END_OBJECT;
} else if (_currToken == JsonToken.START_ARRAY) {
_startContainer = false;
_currToken = JsonToken.END_ARRAY;
}
return this;
}
@Override
public boolean isClosed() {
return _closed;
}
/*
/**********************************************************
/* Public API, token accessors
/**********************************************************
*/
@Override
public String getCurrentName() {
return (_nodeCursor == null) ? null : _nodeCursor.getCurrentName();
}
@Override
public void overrideCurrentName(String name)
{
if (_nodeCursor != null) {
_nodeCursor.overrideCurrentName(name);
}
}
@Override
public JsonStreamContext getParsingContext() {
return _nodeCursor;
}
@Override
public JsonLocation getTokenLocation() {
return JsonLocation.NA;
}
@Override
public JsonLocation getCurrentLocation() {
return JsonLocation.NA;
}
/*
/**********************************************************
/* Public API, access to textual content
/**********************************************************
*/
@Override
public String getText()
{
if (_closed) {
return null;
}
// need to separate handling a bit...
switch (_currToken) {
case FIELD_NAME:
return _nodeCursor.getCurrentName();
case VALUE_STRING:
return currentNode().textValue();
case VALUE_NUMBER_INT:
case VALUE_NUMBER_FLOAT:
return String.valueOf(currentNode().numberValue());
case VALUE_EMBEDDED_OBJECT:
JsonNode n = currentNode();
if (n != null && n.isBinary()) {
// this will convert it to base64
return n.asText();
}
default:
return (_currToken == null) ? null : _currToken.asString();
}
}
@Override
public char[] getTextCharacters() throws IOException, JsonParseException {
return getText().toCharArray();
}
@Override
public int getTextLength() throws IOException, JsonParseException {
return getText().length();
}
@Override
public int getTextOffset() throws IOException, JsonParseException {
return 0;
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> @Override
public boolean hasTextCharacters() {
// generally we do not have efficient access as char[], hence:
return false;
}
/*
/**********************************************************
/* Public API, typed non-text access
/**********************************************************
*/
//public byte getByteValue() throws IOException, JsonParseException
@Override
public NumberType getNumberType() throws IOException, JsonParseException {
JsonNode n = currentNumericNode();
return (n == null) ? null : n.numberType();
}
@Override
public BigInteger getBigIntegerValue() throws IOException, JsonParseException
{
return currentNumericNode().bigIntegerValue();
}
@Override
public BigDecimal getDecimalValue() throws IOException, JsonParseException {
return currentNumericNode().decimalValue();
}
@Override
public double getDoubleValue() throws IOException, JsonParseException {
return currentNumericNode().doubleValue();
}
@Override
public float getFloatValue() throws IOException, JsonParseException {
return (float) currentNumericNode().doubleValue();
}
@Override
public long getLongValue() throws IOException, JsonParseException {
return currentNumericNode().longValue();
}
@Override
public int getIntValue() throws IOException, JsonParseException {
return currentNumericNode().intValue();
}
@Override
public Number getNumberValue() throws IOException, JsonParseException {
return currentNumericNode().numberValue();
}
@Override
public Object getEmbeddedObject()
{
if (!_closed) {
JsonNode n = currentNode();
if (n != null) {
if (n.isPojo()) {
return ((POJONode) n).getPojo();
}
if (n.isBinary()) {
return ((BinaryNode) n).binaryValue();
}
}
}
return null;
}
/*
/**********************************************************
/* Public API, typed binary (base64) access
/**********************************************************
*/
@Override
public byte[] getBinaryValue(Base64Variant b64variant)
throws IOException, JsonParseException
{
// Multiple possibilities...
JsonNode n = currentNode();
if (n != null) { // binary node?
byte[] data = n.binaryValue();
// (or TextNode, which can also convert automatically!)
if (data != null) {
return data;
}
// Or maybe byte[] as POJO?
if (n.isPojo()) {
Object ob = ((POJONode) n).getPojo();
if (ob instanceof byte[]) {
return (byte[]) ob;
}
}
}
// otherwise return null to mark we have no binary content
return null;
}
@Override
public int readBinaryValue(Base64Variant b64variant, OutputStream out)
throws IOException, JsonParseException
{
byte[] data = getBinaryValue(b64variant);
if (data != null) {
out.write(data, 0, data.length);
return data.length;
}
return 0;
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected JsonNode currentNode() {
if (_closed || _nodeCursor == null) {
return null;
}
return _nodeCursor.currentNode();
}
protected JsonNode currentNumericNode()
throws JsonParseException
{
JsonNode n = currentNode();
if (n == null || !n.isNumber()) {
JsonToken t = (n == null) ? null : n.asToken();
throw _constructError("
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>Current token ("+t+") not numeric, can not use numeric value accessors");
}
return n;
}
@Override
protected void _handleEOF() throws JsonParseException {
_throwInternal(); // should never get called
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* <code>JsonNode</code> implementation for efficiently containing 32-bit
* `float` values.
*
* @since 2.2
*/
public class FloatNode extends NumericNode
{
protected final float _value;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
public FloatNode(float v) { _value = v; }
public static FloatNode valueOf(float v) { return new FloatNode(v); }
/*
/**********************************************************
/* BaseJsonNode extended API
/**********************************************************
*/
@Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_FLOAT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.FLOAT; }
/*
/**********************************************************
/* Overrridden JsonNode methods
/**********************************************************
*/
@Override
public boolean isFloatingPointNumber() { return true; }
@Override
public boolean isFloat() { return true; }
@Override public boolean canConvertToInt() {
return (_value >= Integer.MIN_VALUE && _value <= Integer.MAX_VALUE);
}
@Override public boolean canConvertToLong() {
return (_value >= Long.MIN_VALUE && _value <= Long.MAX_VALUE);
}
@Override
public Number numberValue() {
return Float.valueOf(_value);
}
@Override
public short shortValue() { return (short) _value; }
@Override
public int intValue() { return (int) _value; }
@Override
public long longValue() { return (long) _value; }
@Override
public float floatValue() { return (float) _value; }
@Override
public double doubleValue() { return _value; }
@Override
public BigDecimal decimalValue() { return BigDecimal.valueOf(_value); }
@Override
public BigInteger bigIntegerValue() {
return decimalValue().toBigInteger();
}
@Override
public String asText() {
// As per [jackson-databind#707]
// return NumberOutput.toString(_value);
// TODO: in 2.7, call `NumberOutput.toString (added in 2.6); not yet for backwards compat
return Float.toString(_value);
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider) throws IOException
{
jg.writeNumber(_value);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof FloatNode) {
// We must account for NaNs: NaN does not equal NaN, therefore we have
// to use Double.compare().
final float otherValue = ((FloatNode) o)._value;
return Float.compare(_value, otherValue) == 0;
}
return false;
}
@Override
public int hashCode() {
return Float.floatToIntBits(_value);
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
serializeContents(value, gen, provider);
gen.writeEndArray();
}
@Override
public void serializeContents(Object[] value, JsonGenerator gen, SerializerProvider provider) throws IOException
{
final int len = value.length;
if (len == 0) {
return;
}
if (_elementSerializer != null) {
serializeContentsUsing(value, gen, provider, _elementSerializer);
return;
}
if (_valueTypeSerializer != null) {
serializeTypedContents(value, gen, provider);
return;
}
int i = 0;
Object elem = null;
try {
PropertySerializerMap serializers = _dynamicSerializers;
for (; i < len; ++i) {
elem = value[i];
if (elem == null) {
provider.defaultSerializeNull(gen);
continue;
}
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
// To fix [JACKSON-508]
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_elementType, cc), provider);
} else {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
}
serializer.serialize(elem, gen, provider);
}
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
// [JACKSON-55] Need to add reference information
/* 05-Mar-2009, tatu: But one nasty edge is when we get
* StackOverflow: usually due to infinite loop. But that gets
* hidden within an InvocationTargetException...
*/
Throwable t = e;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error) {
throw (Error) t;
}
throw JsonMappingException.wrapWithPath(t, elem, i);
}
}
public void serializeContentsUsing(Object[] value, JsonGenerator jgen, SerializerProvider provider,
JsonSerializer<Object> ser) throws IOException
{
final int len = value.length;
final TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
Object elem = null;
try {
for (; i < len; ++i) {
elem = value[i];
if (elem == null) {
provider.defaultSerializeNull(jgen);
continue;
}
if (typeSer == null) {
ser.serialize(elem, jgen, provider);
} else {
ser.serializeWithType(elem, jgen, provider, typeSer);
}
}
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
Throwable t = e;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error) {
throw (Error) t;
}
throw JsonMappingException.wrapWithPath(t, elem, i);
}
}
public void serialize
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>TypedContents(Object[] value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
final int len = value.length;
final TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
Object elem = null;
try {
PropertySerializerMap serializers = _dynamicSerializers;
for (; i < len; ++i) {
elem = value[i];
if (elem == null) {
provider.defaultSerializeNull(jgen);
continue;
}
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
serializer.serializeWithType(elem, jgen, provider, typeSer);
}
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
Throwable t = e;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error) {
throw (Error) t;
}
throw JsonMappingException.wrapWithPath(t, elem, i);
}
}
@SuppressWarnings("deprecation")
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
ObjectNode o = createSchemaNode("array", true);
if (typeHint != null) {
JavaType javaType = provider.constructType(typeHint);
if (javaType.isArrayType()) {
Class<?> componentType = ((ArrayType) javaType).getContentType().getRawClass();
// 15-Oct-2010, tatu: We can't serialize plain Object.class; but what should it produce here? Untyped?
if (componentType == Object.class) {
o.set("items", com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode());
} else {
JsonSerializer<Object> ser = provider.findValueSerializer(componentType, _property);
JsonNode schemaNode = (ser instanceof SchemaAware) ?
((SchemaAware) ser).getSchema(provider, null) :
com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode();
o.set("items", schemaNode);
}
}
}
return o;
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
JsonArrayFormatVisitor arrayVisitor = visitor.expectArrayFormat(typeHint);
if (arrayVisitor != null) {
TypeFactory tf = visitor.getProvider().getTypeFactory();
JavaType contentType = tf.moreSpecificType(_elementType, typeHint.getContentType());
if (contentType == null) {
throw new JsonMappingException("Could not resolve type");
}
JsonSerializer<?> valueSer = _elementSerializer;
if (valueSer == null) {
valueSer = visitor.getProvider().findValueSerializer(contentType, _property);
}
arrayVisitor.itemsFormat(valueSer, contentType);
}
}
protected final JsonSerializer<Object> _findAndAddDynamic(PropertySerializerMap map,
Class<?> type, SerializerProvider provider) throws JsonMappingException
{
PropertySerializerMap.SerializerAndMapResult result = map.findAndAddSecondarySerializer(type, provider, _property);
// did we get a new map of serializers? If so, start using it
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
/**
* Numeric node that contains values that do not fit in simple
* integer (int, long) or floating point (double) values.
*/
public class DecimalNode
extends NumericNode
{
public static final DecimalNode ZERO = new DecimalNode(BigDecimal.ZERO);
private final static BigDecimal MIN_INTEGER = BigDecimal.valueOf(Integer.MIN_VALUE);
private final static BigDecimal MAX_INTEGER = BigDecimal.valueOf(Integer.MAX_VALUE);
private final static BigDecimal MIN_LONG = BigDecimal.valueOf(Long.MIN_VALUE);
private final static BigDecimal MAX_LONG = BigDecimal.valueOf(Long.MAX_VALUE);
final protected BigDecimal _value;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
public DecimalNode(BigDecimal v) { _value = v; }
public static DecimalNode valueOf(BigDecimal d) { return new DecimalNode(d); }
/*
/**********************************************************
/* BaseJsonNode extended API
/**********************************************************
*/
@Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_FLOAT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.BIG_DECIMAL; }
/*
/**********************************************************
/* Overrridden JsonNode methods
/**********************************************************
*/
@Override
public boolean isFloatingPointNumber() { return true; }
@Override
public boolean isBigDecimal() { return true; }
@Override public boolean canConvertToInt() {
return (_value.compareTo(MIN_INTEGER) >= 0) && (_value.compareTo(MAX_INTEGER) <= 0);
}
@Override public boolean canConvertToLong() {
return (_value.compareTo(MIN_LONG) >= 0) && (_value.compareTo(MAX_LONG) <= 0);
}
@Override
public Number numberValue() { return _value; }
@Override
public short shortValue() { return _value.shortValue(); }
@Override
public int intValue() { return _value.intValue(); }
@Override
public long longValue() { return _value.longValue(); }
@Override
public BigInteger bigIntegerValue() { return _value.toBigInteger(); }
@Override
public float floatValue() { return _value.floatValue(); }
@Override
public double doubleValue() { return _value.doubleValue(); }
@Override
public BigDecimal decimalValue() { return _value; }
@Override
public String asText() {
return _value.toString();
}
@Override
public final void serialize(JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException
{
// 07-Jul-2013, tatu: Should be handled by propagating setting to JsonGenerator
// so this should not be needed:
/*
if (provider.isEnabled(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN)) {
if (!(jgen instanceof TokenBuffer)) { // [Issue#232]
jgen.writeNumber(((BigDecimal) _value).toPlainString());
return;
}
}
*/
jgen.writeNumber(_value);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.util.RawValue;
/**
* This intermediate base class is used for all container nodes,
* specifically, array and object nodes.
*/
public abstract class ContainerNode<T extends ContainerNode<T>>
extends BaseJsonNode
implements JsonNodeCreator
{
/**
* We will keep a reference to the Object (usually TreeMapper)
* that can construct instances of nodes to add to this container
* node.
*/
protected final JsonNodeFactory _nodeFactory;
protected ContainerNode(JsonNodeFactory nc) {
_nodeFactory = nc;
}
// all containers are mutable: can't define:
// @Override public abstract <T extends JsonNode> T deepCopy();
@Override
public abstract JsonToken asToken();
@Override
public String asText() { return ""; }
/*
/**********************************************************
/* Methods reset as abstract to force real implementation
/**********************************************************
*/
@Override
public abstract int size();
@Override
public abstract JsonNode get(int index);
@Override
public abstract JsonNode get(String fieldName);
/*
/**********************************************************
/* JsonNodeCreator implementation, just dispatch to
/* the real creator
/**********************************************************
*/
/**
* Factory method that constructs and returns an empty {@link ArrayNode}
* Construction is done using registered {@link JsonNodeFactory}.
*/
@Override
public final ArrayNode arrayNode() { return _nodeFactory.arrayNode(); }
/**
* Factory method that constructs and returns an empty {@link ObjectNode}
* Construction is done using registered {@link JsonNodeFactory}.
*/
@Override
public final ObjectNode objectNode() { return _nodeFactory.objectNode(); }
@Override
public final NullNode nullNode() { return _nodeFactory.nullNode(); }
@Override
public final BooleanNode booleanNode(boolean v) { return _nodeFactory.booleanNode(v); }
@Override
public final NumericNode numberNode(byte v) { return _nodeFactory.numberNode(v); }
@Override
public final NumericNode numberNode(short v) { return _nodeFactory.numberNode(v); }
@Override
public final NumericNode numberNode(int v) { return _nodeFactory.numberNode(v); }
@Override
public final NumericNode numberNode(long v) {
return _nodeFactory.numberNode(v);
}
// was missing from 2.2 and before
@Override
public final NumericNode numberNode(BigInteger v) { return _nodeFactory.numberNode(v); }
@Override
public final NumericNode numberNode(float v) { return _nodeFactory.numberNode(v); }
@Override
public final NumericNode numberNode(double v) { return _nodeFactory.numberNode(v); }
@Override
public final NumericNode numberNode(BigDecimal v) { return (_nodeFactory.numberNode(v)); }
// // Wrapper types, missing from 2.2 and before
@Override
public final ValueNode numberNode(Byte v) { return _nodeFactory.numberNode(v); }
@Override
public final ValueNode numberNode(Short v) { return _nodeFactory.numberNode(v); }
@Override
public final ValueNode numberNode(Integer v
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
public class StackTraceElementDeserializer
extends StdScalarDeserializer<StackTraceElement>
{
private static final long serialVersionUID = 1L;
public StackTraceElementDeserializer() { super(StackTraceElement.class); }
@Override
public StackTraceElement deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
JsonToken t = jp.getCurrentToken();
// Must get an Object
if (t == JsonToken.START_OBJECT) {
String className = "", methodName = "", fileName = "";
int lineNumber = -1;
while ((t = jp.nextValue()) != JsonToken.END_OBJECT) {
String propName = jp.getCurrentName();
if ("className".equals(propName)) {
className = jp.getText();
} else if ("fileName".equals(propName)) {
fileName = jp.getText();
} else if ("lineNumber".equals(propName)) {
if (t.isNumeric()) {
lineNumber = jp.getIntValue();
} else {
throw JsonMappingException.from(jp, "Non-numeric token ("+t+") for property 'lineNumber'");
}
} else if ("methodName".equals(propName)) {
methodName = jp.getText();
} else if ("nativeMethod".equals(propName)) {
// no setter, not passed via constructor: ignore
} else {
handleUnknownProperty(jp, ctxt, _valueClass, propName);
}
}
return new StackTraceElement(className, methodName, fileName, lineNumber);
} else if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final StackTraceElement value = deserialize(jp, ctxt);
if (jp.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'java.lang.StackTraceElement' value but there was more than a single value in the array"
);
}
return value;
}
throw ctxt.mappingException(_valueClass, t);
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.jsontype.impl;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.DatabindContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import java.util.Collection;
import java.util.HashMap;
import java.util.TreeSet;
public class TypeNameIdResolver extends TypeIdResolverBase
{
protected final MapperConfig<?> _config;
/**
* Mappings from class name to type id, used for serialization
*/
protected final HashMap<String, String> _typeToId;
/**
* Mappings from type id to JavaType, used for deserialization
*/
protected final HashMap<String, JavaType> _idToType;
protected TypeNameIdResolver(MapperConfig<?> config, JavaType baseType,
HashMap<String, String> typeToId, HashMap<String, JavaType> idToType)
{
super(baseType, config.getTypeFactory());
_config = config;
_typeToId = typeToId;
_idToType = idToType;
}
public static TypeNameIdResolver construct(MapperConfig<?> config, JavaType baseType,
Collection<NamedType> subtypes, boolean forSer, boolean forDeser)
{
// sanity check
if (forSer == forDeser) throw new IllegalArgumentException();
HashMap<String, String> typeToId = null;
HashMap<String, JavaType> idToType = null;
if (forSer) {
typeToId = new HashMap<String, String>();
}
if (forDeser) {
idToType = new HashMap<String, JavaType>();
}
if (subtypes != null) {
for (NamedType t : subtypes) {
/* no name? Need to figure out default; for now, let's just
* use non-qualified class name
*/
Class<?> cls = t.getType();
String id = t.hasName() ? t.getName() : _defaultTypeId(cls);
if (forSer) {
typeToId.put(cls.getName(), id);
}
if (forDeser) {
/* 24-Feb-2011, tatu: [JACKSON-498] One more problem; sometimes
* we have same name for multiple types; if so, use most specific
* one.
*/
JavaType prev = idToType.get(id);
if (prev != null) { // Can only override if more specific
if (cls.isAssignableFrom(prev.getRawClass())) { // nope, more generic (or same)
continue;
}
}
idToType.put(id, config.constructType(cls));
}
}
}
return new TypeNameIdResolver(config, baseType, typeToId, idToType);
}
@Override
public JsonTypeInfo.Id getMechanism() { return JsonTypeInfo.Id.NAME; }
@Override
public String idFromValue(Object value)
{
return idFromClass(value.getClass());
}
protected String idFromClass(Class<?> clazz)
{
if(clazz==null){
return null;
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>Id.ID_FALSE:
return Boolean.FALSE;
case JsonTokenId.ID_NULL: // should not get this far really but...
return null;
default:
}
throw ctxt.mappingException(Object.class);
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
/**
* Method called to map a JSON Array into a Java value.
*/
protected Object mapArray(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// Minor optimization to handle small lists (default size for ArrayList is 10)
if (jp.nextToken() == JsonToken.END_ARRAY) {
return new ArrayList<Object>(2);
}
Object value = deserialize(jp, ctxt);
if (jp.nextToken() == JsonToken.END_ARRAY) {
ArrayList<Object> l = new ArrayList<Object>(2);
l.add(value);
return l;
}
Object value2 = deserialize(jp, ctxt);
if (jp.nextToken() == JsonToken.END_ARRAY) {
ArrayList<Object> l = new ArrayList<Object>(2);
l.add(value);
l.add(value2);
return l;
}
ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] values = buffer.resetAndStart();
int ptr = 0;
values[ptr++] = value;
values[ptr++] = value2;
int totalSize = ptr;
do {
value = deserialize(jp, ctxt);
++totalSize;
if (ptr >= values.length) {
values = buffer.appendCompletedChunk(values);
ptr = 0;
}
values[ptr++] = value;
} while (jp.nextToken() != JsonToken.END_ARRAY);
// let's create full array then
ArrayList<Object> result = new ArrayList<Object>(totalSize);
buffer.completeAndClearBuffer(values, ptr, result);
return result;
}
/**
* Method called to map a JSON Object into a Java value.
*/
protected Object mapObject(JsonParser p, DeserializationContext ctxt) throws IOException
{
String key1;
JsonToken t = p.getCurrentToken();
if (t == JsonToken.START_OBJECT) {
key1 = p.nextFieldName();
} else if (t == JsonToken.FIELD_NAME) {
key1 = p.getCurrentName();
} else {
if (t != JsonToken.END_OBJECT) {
throw ctxt.mappingException(handledType(), p.getCurrentToken());
}
key1 = null;
}
if (key1 == null) {
// empty map might work; but caller may want to modify... so better just give small modifiable
return new LinkedHashMap<String,Object>(2);
}
// minor optimization; let's handle 1 and 2 entry cases separately
// 24-Mar-2015, tatu: Ideally, could use one of 'nextXxx()' methods, but for
// that we'd need new method(s) in JsonDeserializer. So not quite yet.
p.nextToken();
Object value1 = deserialize(p, ctxt);
String key2 = p.nextFieldName();
if (key2 == null) { // has to be END_OBJECT, then
// single entry; but we want modifiable
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>(2);
result.put
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>(key1, value1);
return result;
}
p.nextToken();
Object value2 = deserialize(p, ctxt);
String key = p.nextFieldName();
if (key == null) {
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>(4);
result.put(key1, value1);
result.put(key2, value2);
return result;
}
// And then the general case; default map size is 16
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
result.put(key1, value1);
result.put(key2, value2);
do {
p.nextToken();
result.put(key, deserialize(p, ctxt));
} while ((key = p.nextFieldName()) != null);
return result;
}
/**
* Method called to map a JSON Array into a Java Object array (Object[]).
*/
protected Object[] mapArrayToArray(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// Minor optimization to handle small lists (default size for ArrayList is 10)
if (jp.nextToken() == JsonToken.END_ARRAY) {
return NO_OBJECTS;
}
ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] values = buffer.resetAndStart();
int ptr = 0;
do {
Object value = deserialize(jp, ctxt);
if (ptr >= values.length) {
values = buffer.appendCompletedChunk(values);
ptr = 0;
}
values[ptr++] = value;
} while (jp.nextToken() != JsonToken.END_ARRAY);
return buffer.completeAndClearBuffer(values, ptr);
}
/*
/**********************************************************
/* Separate "vanilla" implementation for common case of
/* no custom deserializer overrides
/**********************************************************
*/
@JacksonStdImpl
public static class Vanilla
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static Vanilla std = new Vanilla();
public Vanilla() { super(Object.class); }
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_OBJECT:
{
JsonToken t = p.nextToken();
if (t == JsonToken.END_OBJECT) {
return new LinkedHashMap<String,Object>(2);
}
}
case JsonTokenId.ID_FIELD_NAME:
return mapObject(p, ctxt);
case JsonTokenId.ID_START_ARRAY:
{
JsonToken t = p.nextToken();
if (t == JsonToken.END_ARRAY) { // and empty one too
if (ctxt.isEnabled(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY)) {
return NO_OBJECTS;
}
return new ArrayList<Object>(2);
}
}
if (ctxt.isEnabled(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY)) {
return mapArrayToArray(p, ctxt);
}
return mapArray(p, ctxt);
case JsonTokenId.ID_EMBEDDED_OBJECT:
return p.getEmbeddedObject();
case JsonTokenId.ID_STRING:
return p.getText();
case JsonTokenId.ID_NUMBER_INT:
if (ctxt.hasSomeOfFeatures(
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>F_MASK_INT_COERCIONS)) {
return _coerceIntegral(p, ctxt);
}
return p.getNumberValue(); // should be optimal, whatever it is
case JsonTokenId.ID_NUMBER_FLOAT:
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
return p.getDecimalValue();
}
return Double.valueOf(p.getDoubleValue());
case JsonTokenId.ID_TRUE:
return Boolean.TRUE;
case JsonTokenId.ID_FALSE:
return Boolean.FALSE;
case JsonTokenId.ID_NULL: // should not get this but...
return null;
case JsonTokenId.ID_END_OBJECT:
// 28-Oct-2015, tatu: [databind#989] We may also be given END_OBJECT (similar to FIELD_NAME),
// if caller has advanced to the first token of Object, but for empty Object
return new LinkedHashMap<String,Object>(2);
//case JsonTokenId.ID_END_ARRAY: // invalid
default:
throw ctxt.mappingException(Object.class);
}
}
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException
{
switch (jp.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(jp, ctxt);
case JsonTokenId.ID_STRING:
return jp.getText();
case JsonTokenId.ID_NUMBER_INT:
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS)) {
return jp.getBigIntegerValue();
}
return jp.getNumberValue();
case JsonTokenId.ID_NUMBER_FLOAT:
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
return jp.getDecimalValue();
}
return Double.valueOf(jp.getDoubleValue());
case JsonTokenId.ID_TRUE:
return Boolean.TRUE;
case JsonTokenId.ID_FALSE:
return Boolean.FALSE;
case JsonTokenId.ID_EMBEDDED_OBJECT:
return jp.getEmbeddedObject();
case JsonTokenId.ID_NULL: // should not get this far really but...
return null;
default:
throw ctxt.mappingException(Object.class);
}
}
protected Object mapArray(JsonParser jp, DeserializationContext ctxt) throws IOException
{
Object value = deserialize(jp, ctxt);
if (jp.nextToken() == JsonToken.END_ARRAY) {
ArrayList<Object> l = new ArrayList<Object>(2);
l.add(value);
return l;
}
Object value2 = deserialize(jp, ctxt);
if (jp.nextToken() == JsonToken.END_ARRAY) {
ArrayList<Object> l = new ArrayList<Object>(2);
l.add(value);
l.add(value2);
return l;
}
ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] values = buffer.resetAndStart();
int ptr = 0;
values[ptr++] = value;
values[ptr++] = value2;
int totalSize = ptr;
do {
value = deserialize(jp, ctxt);
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>
++totalSize;
if (ptr >= values.length) {
values = buffer.appendCompletedChunk(values);
ptr = 0;
}
values[ptr++] = value;
} while (jp.nextToken() != JsonToken.END_ARRAY);
// let's create full array then
ArrayList<Object> result = new ArrayList<Object>(totalSize);
buffer.completeAndClearBuffer(values, ptr, result);
return result;
}
/**
* Method called to map a JSON Object into a Java value.
*/
protected Object mapObject(JsonParser p, DeserializationContext ctxt) throws IOException
{
// will point to FIELD_NAME at this point, guaranteed
String key1 = p.getText();
p.nextToken();
Object value1 = deserialize(p, ctxt);
String key2 = p.nextFieldName();
if (key2 == null) { // single entry; but we want modifiable
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>(2);
result.put(key1, value1);
return result;
}
p.nextToken();
Object value2 = deserialize(p, ctxt);
String key = p.nextFieldName();
if (key == null) {
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>(4);
result.put(key1, value1);
result.put(key2, value2);
return result;
}
// And then the general case; default map size is 16
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
result.put(key1, value1);
result.put(key2, value2);
do {
p.nextToken();
result.put(key, deserialize(p, ctxt));
} while ((key = p.nextFieldName()) != null);
return result;
}
/**
* Method called to map a JSON Array into a Java Object array (Object[]).
*/
protected Object[] mapArrayToArray(JsonParser jp, DeserializationContext ctxt) throws IOException {
ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] values = buffer.resetAndStart();
int ptr = 0;
do {
Object value = deserialize(jp, ctxt);
if (ptr >= values.length) {
values = buffer.appendCompletedChunk(values);
ptr = 0;
}
values[ptr++] = value;
} while (jp.nextToken() != JsonToken.END_ARRAY);
return buffer.completeAndClearBuffer(values, ptr);
}
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.jsontype.impl;
import java.io.IOException;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.util.JsonParserSequence;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
import com.fasterxml.jackson.databind.util.TokenBuffer;
/**
* Type deserializer used with {@link As#WRAPPER_OBJECT}
* inclusion mechanism. Simple since JSON structure used is always
* the same, regardless of structure used for actual value: wrapping
* is done using a single-element JSON Object where type id is the key,
* and actual object data as the value.
*/
public class AsWrapperTypeDeserializer
extends TypeDeserializerBase
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
public AsWrapperTypeDeserializer(JavaType bt, TypeIdResolver idRes,
String typePropertyName, boolean typeIdVisible, Class<?> defaultImpl)
{
super(bt, idRes, typePropertyName, typeIdVisible, defaultImpl);
}
protected AsWrapperTypeDeserializer(AsWrapperTypeDeserializer src, BeanProperty property) {
super(src, property);
}
@Override
public TypeDeserializer forProperty(BeanProperty prop) {
return (prop == _property) ? this : new AsWrapperTypeDeserializer(this, prop);
}
@Override
public As getTypeInclusion() { return As.WRAPPER_OBJECT; }
/**
* Deserializing type id enclosed using WRAPPER_OBJECT style is straightforward
*/
@Override
public Object deserializeTypedFromObject(JsonParser jp, DeserializationContext ctxt) throws IOException {
return _deserialize(jp, ctxt);
}
@Override
public Object deserializeTypedFromArray(JsonParser jp, DeserializationContext ctxt) throws IOException {
return _deserialize(jp, ctxt);
}
@Override
public Object deserializeTypedFromScalar(JsonParser jp, DeserializationContext ctxt) throws IOException {
return _deserialize(jp, ctxt);
}
@Override
public Object deserializeTypedFromAny(JsonParser jp, DeserializationContext ctxt) throws IOException {
return _deserialize(jp, ctxt);
}
/*
/***************************************************************
/* Internal methods
/***************************************************************
*/
/**
* Method that handles type information wrapper, locates actual
* subtype deserializer to use, and calls it to do actual
* deserialization.
*/
@SuppressWarnings("resource")
protected Object _deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 02-Aug-2013, tatu: May need to use native type ids
if (p.canReadTypeId()) {
Object typeId = p.getTypeId();
if (typeId != null) {
return _deserializeWithNativeTypeId(p, ctxt, typeId);
}
}
// first, sanity checks
JsonToken t = p.getCurrentToken();
if (t == JsonToken.START_OBJECT) {
// should always get field name, but just in case...
if (p.nextToken() != JsonToken.FIELD_NAME) {
throw ctxt.wrongTokenException(p, JsonToken.FIELD_NAME,
"need JSON String that contains type id (for subtype of "+baseTypeName()+")
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>");
}
} else if (t != JsonToken.FIELD_NAME) {
throw ctxt.wrongTokenException(p, JsonToken.START_OBJECT,
"need JSON Object to contain As.WRAPPER_OBJECT type information for class "+baseTypeName());
}
final String typeId = p.getText();
JsonDeserializer<Object> deser = _findDeserializer(ctxt, typeId);
p.nextToken();
// Minor complication: we may need to merge type id in?
if (_typeIdVisible && p.getCurrentToken() == JsonToken.START_OBJECT) {
// but what if there's nowhere to add it in? Error? Or skip? For now, skip.
TokenBuffer tb = new TokenBuffer(null, false);
tb.writeStartObject(); // recreate START_OBJECT
tb.writeFieldName(_typePropertyName);
tb.writeString(typeId);
p = JsonParserSequence.createFlattened(tb.asParser(p), p);
p.nextToken();
}
Object value = deser.deserialize(p, ctxt);
// And then need the closing END_OBJECT
if (p.nextToken() != JsonToken.END_OBJECT) {
throw ctxt.wrongTokenException(p, JsonToken.END_OBJECT,
"expected closing END_OBJECT after type information and deserialized value");
}
return value;
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> {@link ObjectMapper#enableDefaultTyping()}
* to specify what kind of types (classes) default typing should
* be used for. It will only be used if no explicit type information
* is found, but this enumeration further limits subset of those types.
*<p>
* Since 2.4 there are special exceptions for JSON Tree model
* types (sub-types of {@link TreeNode}: default typing is never
* applied to them
* (see <a href="https://github.com/FasterXML/jackson-databind/issues/88">Issue#88</a> for details)
*/
public enum DefaultTyping {
/**
* This value means that only properties that have
* {@link java.lang.Object} as declared type (including
* generic types without explicit type) will use default
* typing.
*/
JAVA_LANG_OBJECT,
/**
* Value that means that default typing will be used for
* properties with declared type of {@link java.lang.Object}
* or an abstract type (abstract class or interface).
* Note that this does <b>not</b> include array types.
*<p>
* Since 2.4, this does NOT apply to {@link TreeNode} and its subtypes.
*/
OBJECT_AND_NON_CONCRETE,
/**
* Value that means that default typing will be used for
* all types covered by {@link #OBJECT_AND_NON_CONCRETE}
* plus all array types for them.
*<p>
* Since 2.4, this does NOT apply to {@link TreeNode} and its subtypes.
*/
NON_CONCRETE_AND_ARRAYS,
/**
* Value that means that default typing will be used for
* all non-final types, with exception of small number of
* "natural" types (String, Boolean, Integer, Double), which
* can be correctly inferred from JSON; as well as for
* all arrays of non-final types.
*<p>
* Since 2.4, this does NOT apply to {@link TreeNode} and its subtypes.
*/
NON_FINAL
}
/**
* Customized {@link TypeResolverBuilder} that provides type resolver builders
* used with so-called "default typing"
* (see {@link ObjectMapper#enableDefaultTyping()} for details).
*<p>
* Type resolver construction is based on configuration: implementation takes care
* of only providing builders in cases where type information should be applied.
* This is important since build calls may be sent for any and all types, and
* type information should NOT be applied to all of them.
*/
public static class DefaultTypeResolverBuilder
extends StdTypeResolverBuilder
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Definition of what types is this default typer valid for.
*/
protected final DefaultTyping _appliesFor;
public DefaultTypeResolverBuilder(DefaultTyping t) {
_appliesFor = t;
}
@Override
public TypeDeserializer buildTypeDeserializer(DeserializationConfig config,
JavaType baseType, Collection<NamedType> subtypes)
{
return useForType(baseType) ? super.buildTypeDeserializer(config, baseType, subtypes) : null;
}
@Override
public TypeSerializer buildTypeSerializer(SerializationConfig config,
JavaType baseType, Collection<NamedType> subtypes)
{
return useForType(
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>baseType) ? super.buildTypeSerializer(config, baseType, subtypes) : null;
}
/**
* Method called to check if the default type handler should be
* used for given type.
* Note: "natural types" (String, Boolean, Integer, Double) will never
* use typing; that is both due to them being concrete and final,
* and since actual serializers and deserializers will also ignore any
* attempts to enforce typing.
*/
public boolean useForType(JavaType t)
{
switch (_appliesFor) {
case NON_CONCRETE_AND_ARRAYS:
while (t.isArrayType()) {
t = t.getContentType();
}
// fall through
case OBJECT_AND_NON_CONCRETE:
return t.isJavaLangObject()
|| (!t.isConcrete()
// [databind#88] Should not apply to JSON tree models:
&& !TreeNode.class.isAssignableFrom(t.getRawClass()));
case NON_FINAL:
while (t.isArrayType()) {
t = t.getContentType();
}
// [Issue#88] Should not apply to JSON tree models:
return !t.isFinal() && !TreeNode.class.isAssignableFrom(t.getRawClass());
default:
//case JAVA_LANG_OBJECT:
return t.isJavaLangObject();
}
}
}
/*
/**********************************************************
/* Internal constants, singletons
/**********************************************************
*/
// Quick little shortcut, to avoid having to use global TypeFactory instance...
private final static JavaType JSON_NODE_TYPE = SimpleType.constructUnsafe(JsonNode.class);
// 16-May-2009, tatu: Ditto ^^^
protected final static AnnotationIntrospector DEFAULT_ANNOTATION_INTROSPECTOR = new JacksonAnnotationIntrospector();
protected final static VisibilityChecker<?> STD_VISIBILITY_CHECKER = VisibilityChecker.Std.defaultInstance();
/**
* @deprecated Since 2.6, do not use: will be removed in 2.7 or later
*/
@Deprecated
protected final static PrettyPrinter _defaultPrettyPrinter = new DefaultPrettyPrinter();
/**
* Base settings contain defaults used for all {@link ObjectMapper}
* instances.
*/
protected final static BaseSettings DEFAULT_BASE = new BaseSettings(
null, // can not share global ClassIntrospector any more (2.5+)
DEFAULT_ANNOTATION_INTROSPECTOR,
STD_VISIBILITY_CHECKER, null, TypeFactory.defaultInstance(),
null, StdDateFormat.instance, null,
Locale.getDefault(),
null, // to indicate "use default TimeZone"
Base64Variants.getDefaultVariant() // 2.1
);
/*
/**********************************************************
/* Configuration settings, shared
/**********************************************************
*/
/**
* Factory used to create {@link JsonParser} and {@link JsonGenerator}
* instances as necessary.
*/
protected final JsonFactory _jsonFactory;
/**
* Specific factory used for creating {@link JavaType} instances;
* needed to allow modules to add more custom type handling
* (mostly to support types of non-Java JVM languages)
*/
protected TypeFactory _typeFactory;
/**
* Provider for values to inject in deserialized POJOs.
*/
protected InjectableValues _injectableValues;
/**
* Thing used for registering sub-types, resolving them to
* super/sub-types as needed
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>jackson.annotation.JsonTypeInfo}) --
* using "As.PROPERTY" inclusion mechanism and specified property name
* to use for inclusion (default being "@class" since default type information
* always uses class name as type identifier)
*/
public ObjectMapper enableDefaultTypingAsProperty(DefaultTyping applicability, String propertyName)
{
TypeResolverBuilder<?> typer = new DefaultTypeResolverBuilder(applicability);
// we'll always use full class name, when using defaulting
typer = typer.init(JsonTypeInfo.Id.CLASS, null);
typer = typer.inclusion(JsonTypeInfo.As.PROPERTY);
typer = typer.typeProperty(propertyName);
return setDefaultTyping(typer);
}
/**
* Method for disabling automatic inclusion of type information; if so, only
* explicitly annotated types (ones with
* {@link com.fasterxml.jackson.annotation.JsonTypeInfo}) will have
* additional embedded type information.
*/
public ObjectMapper disableDefaultTyping() {
return setDefaultTyping(null);
}
/**
* Method for enabling automatic inclusion of type information, using
* specified handler object for determining which types this affects,
* as well as details of how information is embedded.
*
* @param typer Type information inclusion handler
*/
public ObjectMapper setDefaultTyping(TypeResolverBuilder<?> typer) {
_deserializationConfig = _deserializationConfig.with(typer);
_serializationConfig = _serializationConfig.with(typer);
return this;
}
/**
* Method for registering specified class as a subtype, so that
* typename-based resolution can link supertypes to subtypes
* (as an alternative to using annotations).
* Type for given class is determined from appropriate annotation;
* or if missing, default name (unqualified class name)
*/
public void registerSubtypes(Class<?>... classes) {
getSubtypeResolver().registerSubtypes(classes);
}
/**
* Method for registering specified class as a subtype, so that
* typename-based resolution can link supertypes to subtypes
* (as an alternative to using annotations).
* Name may be provided as part of argument, but if not will
* be based on annotations or use default name (unqualified
* class name).
*/
public void registerSubtypes(NamedType... types) {
getSubtypeResolver().registerSubtypes(types);
}
/*
/**********************************************************
/* Configuration, basic type handling
/**********************************************************
*/
/**
* Accessor for getting currently configured {@link TypeFactory} instance.
*/
public TypeFactory getTypeFactory() {
return _typeFactory;
}
/**
* Method that can be used to override {@link TypeFactory} instance
* used by this mapper.
*<p>
* Note: will also set {@link TypeFactory} that deserialization and
* serialization config objects use.
*/
public ObjectMapper setTypeFactory(TypeFactory f)
{
_typeFactory = f;
_deserializationConfig = _deserializationConfig.with(f);
_serializationConfig = _serializationConfig.with(f);
return this;
}
/**
* Convenience method for constructing {@link JavaType} out of given
* type (typically <code>java.lang.Class</code>), but without explicit
* context.
*/
public JavaType constructType(Type t) {
return _typeFactory.constructType(t);
}
/*
/**********************************************************
/* Configuration, deserialization
/********************************************************
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> network error) occurs (passed through as-is without additional wrapping -- note
* that this is one case where {@link DeserializationFeature#WRAP_EXCEPTIONS}
* does NOT result in wrapping of exception even if enabled)
* @throws JsonParseException if underlying input contains invalid content
* of type {@link JsonParser} supports (JSON for default case)
* @throws JsonMappingException if the input JSON structure does not match structure
* expected for result type (or has other mismatch issues)
*/
@SuppressWarnings("unchecked")
public <T> T readValue(JsonParser jp, JavaType valueType)
throws IOException, JsonParseException, JsonMappingException
{
return (T) _readValue(getDeserializationConfig(), jp, valueType);
}
/**
* Method to deserialize JSON content as tree expressed
* using set of {@link JsonNode} instances. Returns
* root of the resulting tree (where root can consist
* of just a single node if the current event is a
* value event, not container).
*
* @return a {@link JsonNode}, if valid JSON content found; null
* if input has no content to bind -- note, however, that if
* JSON <code>null</code> token is found, it will be represented
* as a non-null {@link JsonNode} (one that returns <code>true</code>
* for {@link JsonNode#isNull()}
*
* @throws IOException if a low-level I/O problem (unexpected end-of-input,
* network error) occurs (passed through as-is without additional wrapping -- note
* that this is one case where {@link DeserializationFeature#WRAP_EXCEPTIONS}
* does NOT result in wrapping of exception even if enabled)
* @throws JsonParseException if underlying input contains invalid content
* of type {@link JsonParser} supports (JSON for default case)
*/
@Override
public <T extends TreeNode> T readTree(JsonParser jp)
throws IOException, JsonProcessingException
{
/* 02-Mar-2009, tatu: One twist; deserialization provider
* will map JSON null straight into Java null. But what
* we want to return is the "null node" instead.
*/
/* 05-Aug-2011, tatu: Also, must check for EOF here before
* calling readValue(), since that'll choke on it otherwise
*/
DeserializationConfig cfg = getDeserializationConfig();
JsonToken t = jp.getCurrentToken();
if (t == null) {
t = jp.nextToken();
if (t == null) {
return null;
}
}
JsonNode n = (JsonNode) _readValue(cfg, jp, JSON_NODE_TYPE);
if (n == null) {
n = getNodeFactory().nullNode();
}
@SuppressWarnings("unchecked")
T result = (T) n;
return result;
}
/**
* Method for reading sequence of Objects from parser stream.
* Sequence can be either root-level "unwrapped" sequence (without surrounding
* JSON array), or a sequence contained in a JSON Array.
* In either case {@link JsonParser} must point to the first token of
* the first element, OR not point to any token (in which case it is advanced
* to the next token). This means, specifically, that for wrapped sequences,
* parser MUST NOT point to the surrounding <code>START_ARRAY</
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> can be a Collection or Map
* as well, but NOT an array) with JSON data. Deserialization occurs
* normally except that the root-level value in JSON is not used for
* instantiating a new object; instead give updateable object is used
* as root.
* Runtime type of value object is used for locating deserializer,
* unless overridden by other factory methods of {@link ObjectReader}
*/
public ObjectReader readerForUpdating(Object valueToUpdate) {
JavaType t = _typeFactory.constructType(valueToUpdate.getClass());
return _newReader(getDeserializationConfig(), t, valueToUpdate,
null, _injectableValues);
}
/**
* Factory method for constructing {@link ObjectReader} that will
* read or update instances of specified type
*
* @since 2.6
*/
public ObjectReader readerFor(JavaType type) {
return _newReader(getDeserializationConfig(), type, null,
null, _injectableValues);
}
/**
* Factory method for constructing {@link ObjectReader} that will
* read or update instances of specified type
*
* @since 2.6
*/
public ObjectReader readerFor(Class<?> type) {
return _newReader(getDeserializationConfig(), _typeFactory.constructType(type), null,
null, _injectableValues);
}
/**
* Factory method for constructing {@link ObjectReader} that will
* read or update instances of specified type
*
* @since 2.6
*/
public ObjectReader readerFor(TypeReference<?> type) {
return _newReader(getDeserializationConfig(), _typeFactory.constructType(type), null,
null, _injectableValues);
}
/**
* Factory method for constructing {@link ObjectReader} that will
* use specified {@link JsonNodeFactory} for constructing JSON trees.
*/
public ObjectReader reader(JsonNodeFactory f) {
return _newReader(getDeserializationConfig()).with(f);
}
/**
* Factory method for constructing {@link ObjectReader} that will
* pass specific schema object to {@link JsonParser} used for
* reading content.
*
* @param schema Schema to pass to parser
*/
public ObjectReader reader(FormatSchema schema) {
_verifySchemaType(schema);
return _newReader(getDeserializationConfig(), null, null,
schema, _injectableValues);
}
/**
* Factory method for constructing {@link ObjectReader} that will
* use specified injectable values.
*
* @param injectableValues Injectable values to use
*/
public ObjectReader reader(InjectableValues injectableValues) {
return _newReader(getDeserializationConfig(), null, null,
null, injectableValues);
}
/**
* Factory method for constructing {@link ObjectReader} that will
* deserialize objects using specified JSON View (filter).
*/
public ObjectReader readerWithView(Class<?> view) {
return _newReader(getDeserializationConfig().withView(view));
}
/**
* Factory method for constructing {@link ObjectReader} that will
* use specified Base64 encoding variant for Base64-encoded binary data.
*
* @since 2.1
*/
public ObjectReader reader(Base64Variant defaultBase64) {
return _newReader(getDeserializationConfig().with(defaultBase64));
}
/**
* Factory method for constructing {@link ObjectReader} that will
* use specified default attributes.
*
*
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>Type toValueType)
throws IllegalArgumentException
{
// sanity check for null first:
if (fromValue == null) return null;
return (T) _convert(fromValue, toValueType);
}
/**
* Actual conversion implementation: instead of using existing read
* and write methods, much of code is inlined. Reason for this is
* that we must avoid root value wrapping/unwrapping both for efficiency and
* for correctness. If root value wrapping/unwrapping is actually desired,
* caller must use explicit <code>writeValue</code> and
* <code>readValue</code> methods.
*/
@SuppressWarnings("resource")
protected Object _convert(Object fromValue, JavaType toValueType)
throws IllegalArgumentException
{
// also, as per [Issue-11], consider case for simple cast
/* But with caveats: one is that while everything is Object.class, we don't
* want to "optimize" that out; and the other is that we also do not want
* to lose conversions of generic types.
*/
Class<?> targetType = toValueType.getRawClass();
if (targetType != Object.class
&& !toValueType.hasGenericTypes()
&& targetType.isAssignableFrom(fromValue.getClass())) {
return fromValue;
}
// Then use TokenBuffer, which is a JsonGenerator:
TokenBuffer buf = new TokenBuffer(this, false);
if (isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
buf = buf.forceUseOfBigDecimal(true);
}
try {
// inlined 'writeValue' with minor changes:
// first: disable wrapping when writing
SerializationConfig config = getSerializationConfig().without(SerializationFeature.WRAP_ROOT_VALUE);
// no need to check for closing of TokenBuffer
_serializerProvider(config).serializeValue(buf, fromValue);
// then matching read, inlined 'readValue' with minor mods:
final JsonParser jp = buf.asParser();
Object result;
// ok to pass in existing feature flags; unwrapping handled by mapper
final DeserializationConfig deserConfig = getDeserializationConfig();
JsonToken t = _initForReading(jp);
if (t == JsonToken.VALUE_NULL) {
DeserializationContext ctxt = createDeserializationContext(jp, deserConfig);
result = _findRootDeserializer(ctxt, toValueType).getNullValue(ctxt);
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
result = null;
} else { // pointing to event other than null
DeserializationContext ctxt = createDeserializationContext(jp, deserConfig);
JsonDeserializer<Object> deser = _findRootDeserializer(ctxt, toValueType);
// note: no handling of unwarpping
result = deser.deserialize(jp, ctxt);
}
jp.close();
return result;
} catch (IOException e) { // should not occur, no real i/o...
throw new IllegalArgumentException(e.getMessage(), e);
}
}
/*
/**********************************************************
/* Extended Public API: JSON Schema generation
/**********************************************************
*/
/**
* Generate <a href="http://json-schema.org/">Json-schema</a>
* instance for specified class.
*
* @param t The class to generate schema for
* @return Constructed JSON schema.
*
* @deprecated Since 2.6 use external JSON Schema generator (https://github.com/FasterXML/jackson-
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>module-jsonSchema)
*/
@Deprecated
public com.fasterxml.jackson.databind.jsonschema.JsonSchema generateJsonSchema(Class<?> t)
throws JsonMappingException {
return _serializerProvider(getSerializationConfig()).generateJsonSchema(t);
}
/**
* Method for visiting type hierarchy for given type, using specified visitor.
*<p>
* This method can be used for things like
* generating <a href="http://json-schema.org/">JSON Schema</a>
* instance for specified type.
*
* @param type Type to generate schema for (possibly with generic signature)
*
* @since 2.1
*/
public void acceptJsonFormatVisitor(Class<?> type, JsonFormatVisitorWrapper visitor)
throws JsonMappingException
{
acceptJsonFormatVisitor(_typeFactory.constructType(type), visitor);
}
/**
* Method for visiting type hierarchy for given type, using specified visitor.
* Visitation uses <code>Serializer</code> hierarchy and related properties
*<p>
* This method can be used for things like
* generating <a href="http://json-schema.org/">JSON Schema</a>
* instance for specified type.
*
* @param type Type to generate schema for (possibly with generic signature)
*
* @since 2.1
*/
public void acceptJsonFormatVisitor(JavaType type, JsonFormatVisitorWrapper visitor)
throws JsonMappingException
{
if (type == null) {
throw new IllegalArgumentException("type must be provided");
}
_serializerProvider(getSerializationConfig()).acceptJsonFormatVisitor(type, visitor);
}
/*
/**********************************************************
/* Internal methods for serialization, overridable
/**********************************************************
*/
/**
* Overridable helper method used for constructing
* {@link SerializerProvider} to use for serialization.
*/
protected DefaultSerializerProvider _serializerProvider(SerializationConfig config) {
return _serializerProvider.createInstance(config, _serializerFactory);
}
/**
* @deprecated Since 2.6, use {@link SerializationConfig#constructDefaultPrettyPrinter()} directly
*/
@Deprecated
protected PrettyPrinter _defaultPrettyPrinter() {
return _serializationConfig.constructDefaultPrettyPrinter();
}
/**
* Method called to configure the generator as necessary and then
* call write functionality
*/
protected final void _configAndWriteValue(JsonGenerator g, Object value)
throws IOException
{
SerializationConfig cfg = getSerializationConfig();
cfg.initialize(g); // since 2.5
if (cfg.isEnabled(SerializationFeature.CLOSE_CLOSEABLE) && (value instanceof Closeable)) {
_configAndWriteCloseable(g, value, cfg);
return;
}
boolean closed = false;
try {
_serializerProvider(cfg).serializeValue(g, value);
closed = true;
g.close();
} finally {
/* won't try to close twice; also, must catch exception (so it
* will not mask exception that is pending)
*/
if (!closed) {
/* 04-Mar-2014, tatu: But! Let's try to prevent auto-closing of
* structures, which typically causes more damage.
*/
g.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT);
try {
g.close();
} catch (IOException ioe) { }
}
}
}
protected final void _configAndWriteValue(JsonGenerator g,
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> */
protected DefaultDeserializationContext createDeserializationContext(JsonParser jp,
DeserializationConfig cfg) {
return _deserializationContext.createInstance(cfg, jp, _injectableValues);
}
/**
* Actual implementation of value reading+binding operation.
*/
protected Object _readValue(DeserializationConfig cfg, JsonParser jp, JavaType valueType)
throws IOException, JsonParseException, JsonMappingException
{
/* First: may need to read the next token, to initialize
* state (either before first read from parser, or after
* previous token has been cleared)
*/
Object result;
JsonToken t = _initForReading(jp);
if (t == JsonToken.VALUE_NULL) {
// [JACKSON-643]: Ask JsonDeserializer what 'null value' to use:
DeserializationContext ctxt = createDeserializationContext(jp, cfg);
result = _findRootDeserializer(ctxt, valueType).getNullValue(ctxt);
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
result = null;
} else { // pointing to event other than null
DeserializationContext ctxt = createDeserializationContext(jp, cfg);
JsonDeserializer<Object> deser = _findRootDeserializer(ctxt, valueType);
// ok, let's get the value
if (cfg.useRootWrapping()) {
result = _unwrapAndDeserialize(jp, ctxt, cfg, valueType, deser);
} else {
result = deser.deserialize(jp, ctxt);
}
}
// Need to consume the token too
jp.clearCurrentToken();
return result;
}
protected Object _readMapAndClose(JsonParser jp, JavaType valueType)
throws IOException, JsonParseException, JsonMappingException
{
try {
Object result;
JsonToken t = _initForReading(jp);
if (t == JsonToken.VALUE_NULL) {
// [JACKSON-643]: Ask JsonDeserializer what 'null value' to use:
DeserializationContext ctxt = createDeserializationContext(jp,
getDeserializationConfig());
result = _findRootDeserializer(ctxt, valueType).getNullValue(ctxt);
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
result = null;
} else {
DeserializationConfig cfg = getDeserializationConfig();
DeserializationContext ctxt = createDeserializationContext(jp, cfg);
JsonDeserializer<Object> deser = _findRootDeserializer(ctxt, valueType);
if (cfg.useRootWrapping()) {
result = _unwrapAndDeserialize(jp, ctxt, cfg, valueType, deser);
} else {
result = deser.deserialize(jp, ctxt);
}
ctxt.checkUnresolvedObjectId();
}
// Need to consume the token too
jp.clearCurrentToken();
return result;
} finally {
try {
jp.close();
} catch (IOException ioe) { }
}
}
/**
* Method called to ensure that given parser is ready for reading
* content for data binding.
*
* @return First token to be used for data binding after this call:
* can never be null as exception will be thrown if parser can not
* provide more tokens.
*
* @throws IOException if the underlying input source has problems during
* parsing
* @throws JsonParseException if parser has problems parsing content
* @throws JsonMappingException if the parser does not have any
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> more
* content to map (note: Json "null" value is considered content;
* enf-of-stream not)
*/
protected JsonToken _initForReading(JsonParser p) throws IOException
{
_deserializationConfig.initialize(p); // since 2.5
/* First: must point to a token; if not pointing to one, advance.
* This occurs before first read from JsonParser, as well as
* after clearing of current token.
*/
JsonToken t = p.getCurrentToken();
if (t == null) {
// and then we must get something...
t = p.nextToken();
if (t == null) {
/* [JACKSON-546] Throw mapping exception, since it's failure to map,
* not an actual parsing problem
*/
throw JsonMappingException.from(p, "No content to map due to end-of-input");
}
}
return t;
}
protected Object _unwrapAndDeserialize(JsonParser p, DeserializationContext ctxt,
DeserializationConfig config,
JavaType rootType, JsonDeserializer<Object> deser)
throws IOException
{
PropertyName expRootName = config.findRootName(rootType);
// 12-Jun-2015, tatu: Should try to support namespaces etc but...
String expSimpleName = expRootName.getSimpleName();
if (p.getCurrentToken() != JsonToken.START_OBJECT) {
throw JsonMappingException.from(p, "Current token not START_OBJECT (needed to unwrap root name '"
+expSimpleName+"'), but "+p.getCurrentToken());
}
if (p.nextToken() != JsonToken.FIELD_NAME) {
throw JsonMappingException.from(p, "Current token not FIELD_NAME (to contain expected root name '"
+expSimpleName+"'), but "+p.getCurrentToken());
}
String actualName = p.getCurrentName();
if (!expSimpleName.equals(actualName)) {
throw JsonMappingException.from(p, "Root name '"+actualName+"' does not match expected ('"
+expSimpleName+"') for type "+rootType);
}
// ok, then move to value itself....
p.nextToken();
Object result = deser.deserialize(p, ctxt);
// and last, verify that we now get matching END_OBJECT
if (p.nextToken() != JsonToken.END_OBJECT) {
throw JsonMappingException.from(p, "Current token not END_OBJECT (to match wrapper object with root name '"
+expSimpleName+"'), but "+p.getCurrentToken());
}
return result;
}
/*
/**********************************************************
/* Internal methods, other
/**********************************************************
*/
/**
* Method called to locate deserializer for the passed root-level value.
*/
protected JsonDeserializer<Object> _findRootDeserializer(DeserializationContext ctxt,
JavaType valueType)
throws JsonMappingException
{
// First: have we already seen it?
JsonDeserializer<Object> deser = _rootDeserializers.get(valueType);
if (deser != null) {
return deser;
}
// Nope: need to ask provider to resolve it
deser = ctxt.findRootValueDeserializer(valueType);
if (deser == null) { // can this happen?
throw new JsonMappingException("Can not find a deserializer for type "+valueType);
}
_rootDeserializers.put(valueType
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>Count() == 0) {
return m.getRawType().getName();
}
return am.getRawParameterType(0).getName();
}
return id;
}
@Override
public Class<?>[] findViews(Annotated a)
{
JsonView ann = _findAnnotation(a, JsonView.class);
return (ann == null) ? null : ann.value();
}
/*
/**********************************************************
/* Annotations for Polymorphic Type handling
/**********************************************************
*/
@Override
public TypeResolverBuilder<?> findTypeResolver(MapperConfig<?> config,
AnnotatedClass ac, JavaType baseType)
{
return _findTypeResolver(config, ac, baseType);
}
@Override
public TypeResolverBuilder<?> findPropertyTypeResolver(MapperConfig<?> config,
AnnotatedMember am, JavaType baseType)
{
/* As per definition of @JsonTypeInfo, should only apply to contents of container
* (collection, map) types, not container types themselves:
*/
if (baseType.isContainerType()) return null;
// No per-member type overrides (yet)
return _findTypeResolver(config, am, baseType);
}
@Override
public TypeResolverBuilder<?> findPropertyContentTypeResolver(MapperConfig<?> config,
AnnotatedMember am, JavaType containerType)
{
/* First: let's ensure property is a container type: caller should have
* verified but just to be sure
*/
if (!containerType.isContainerType()) {
throw new IllegalArgumentException("Must call method with a container type (got "+containerType+")");
}
return _findTypeResolver(config, am, containerType);
}
@Override
public List<NamedType> findSubtypes(Annotated a)
{
JsonSubTypes t = _findAnnotation(a, JsonSubTypes.class);
if (t == null) return null;
JsonSubTypes.Type[] types = t.value();
ArrayList<NamedType> result = new ArrayList<NamedType>(types.length);
for (JsonSubTypes.Type type : types) {
result.add(new NamedType(type.value(), type.name()));
}
return result;
}
@Override
public String findTypeName(AnnotatedClass ac)
{
JsonTypeName tn = _findAnnotation(ac, JsonTypeName.class);
return (tn == null) ? null : tn.value();
}
@Override
public Boolean isTypeId(AnnotatedMember member) {
return _hasAnnotation(member, JsonTypeId.class);
}
/*
/**********************************************************
/* Annotations for Object Id handling
/**********************************************************
*/
@Override
public ObjectIdInfo findObjectIdInfo(Annotated ann) {
JsonIdentityInfo info = _findAnnotation(ann, JsonIdentityInfo.class);
if (info == null || info.generator() == ObjectIdGenerators.None.class) {
return null;
}
// In future may need to allow passing namespace?
PropertyName name = PropertyName.construct(info.property());
return new ObjectIdInfo(name, info.scope(), info.generator(), info.resolver());
}
@Override
public ObjectIdInfo findObjectReferenceInfo(Annotated ann, ObjectIdInfo objectIdInfo) {
JsonIdentityReference ref = _findAnnotation(ann, JsonIdentityReference.class);
if (ref != null) {
objectIdInfo = objectIdInfo.withAlwaysAsId(ref.alwaysAsId());
}
return objectIdInfo;
}
/*
/
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> readPropertyValue(p, prop, getTypeFactory().constructType(type));
}
/**
* @since 2.4
*/
@SuppressWarnings("unchecked")
public <T> T readPropertyValue(JsonParser p, BeanProperty prop, JavaType type) throws IOException {
JsonDeserializer<Object> deser = findContextualValueDeserializer(type, prop);
if (deser == null) {
String propName = (prop == null) ? "NULL" : ("'"+prop.getName()+"'");
throw mappingException("Could not find JsonDeserializer for type %s (via property %s)",
type, propName);
}
return (T) deser.deserialize(p, this);
}
/*
/**********************************************************
/* Methods for problem handling, reporting
/**********************************************************
*/
/**
* Method deserializers can call to inform configured {@link DeserializationProblemHandler}s
* of an unrecognized property.
*
* @return True if there was a configured problem handler that was able to handle the
* problem
*/
/**
* Method deserializers can call to inform configured {@link DeserializationProblemHandler}s
* of an unrecognized property.
*/
public boolean handleUnknownProperty(JsonParser p, JsonDeserializer<?> deser,
Object instanceOrClass, String propName)
throws IOException, JsonProcessingException
{
LinkedNode<DeserializationProblemHandler> h = _config.getProblemHandlers();
if (h != null) {
while (h != null) {
// Can bail out if it's handled
if (h.value().handleUnknownProperty(this, p, deser, instanceOrClass, propName)) {
return true;
}
h = h.next();
}
}
return false;
}
/**
* Helper method for reporting a problem with unhandled unknown exception
*
* @param instanceOrClass Either value being populated (if one has been
* instantiated), or Class that indicates type that would be (or
* have been) instantiated
* @param deser Deserializer that had the problem, if called by deserializer
* (or on behalf of one)
*/
public void reportUnknownProperty(Object instanceOrClass, String fieldName,
JsonDeserializer<?> deser)
throws JsonMappingException
{
if (!isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) {
return;
}
// Do we know properties that are expected instead?
Collection<Object> propIds = (deser == null) ? null : deser.getKnownPropertyNames();
throw UnrecognizedPropertyException.from(_parser,
instanceOrClass, fieldName, propIds);
}
/*
/**********************************************************
/* Methods for constructing exceptions
/**********************************************************
*/
/**
* Helper method for constructing generic mapping exception for specified type
*/
public JsonMappingException mappingException(Class<?> targetClass) {
return mappingException(targetClass, _parser.getCurrentToken());
}
public JsonMappingException mappingException(Class<?> targetClass, JsonToken token) {
return JsonMappingException.from(_parser,
String.format("Can not deserialize instance of %s out of %s token",
_calcName(targetClass), token));
}
/**
* Helper method for constructing generic mapping exception with specified
* message and current location information
*/
public JsonMappingException mappingException(String message) {
return JsonMappingException.from(getParser(), message);
}
/**
* Helper method for constructing generic mapping exception with specified
* message and current location information
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>
*
* @since 2.6
*/
public JsonMappingException mappingException(String msgTemplate, Object... args) {
String message = String.format(msgTemplate, args);
return JsonMappingException.from(getParser(), message);
}
/**
* Helper method for constructing instantiation exception for specified type,
* to indicate problem with physically constructing instance of
* specified class (missing constructor, exception from constructor)
*/
public JsonMappingException instantiationException(Class<?> instClass, Throwable t) {
return JsonMappingException.from(_parser,
String.format("Can not construct instance of %s, problem: %s", instClass.getName(), t.getMessage()), t);
}
public JsonMappingException instantiationException(Class<?> instClass, String msg) {
return JsonMappingException.from(_parser,
String.format("Can not construct instance of %s, problem: %s", instClass.getName(), msg));
}
/**
* Method that will construct an exception suitable for throwing when
* some String values are acceptable, but the one encountered is not.
*
* @param value String value from input being deserialized
* @param instClass Type that String should be deserialized into
* @param msg Message that describes specific problem
*
* @since 2.1
*/
public JsonMappingException weirdStringException(String value, Class<?> instClass, String msg) {
return InvalidFormatException.from(_parser,
String.format("Can not construct instance of %s from String value '%s': %s",
instClass.getName(), _valueDesc(), msg),
value, instClass);
}
/**
* Helper method for constructing exception to indicate that input JSON
* Number was not suitable for deserializing into given target type.
*/
public JsonMappingException weirdNumberException(Number value, Class<?> instClass, String msg) {
return InvalidFormatException.from(_parser,
String.format("Can not construct instance of %s from number value (%s): %s",
instClass.getName(), _valueDesc(), msg),
null, instClass);
}
/**
* Helper method for constructing exception to indicate that given JSON
* Object field name was not in format to be able to deserialize specified
* key type.
*/
public JsonMappingException weirdKeyException(Class<?> keyClass, String keyValue, String msg) {
return InvalidFormatException.from(_parser,
String.format("Can not construct Map key of type %s from String \"%s\": ",
keyClass.getName(), _desc(keyValue), msg),
keyValue, keyClass);
}
/**
* Helper method for indicating that the current token was expected to be another
* token.
*/
public JsonMappingException wrongTokenException(JsonParser p, JsonToken expToken, String msg0) {
String msg = String.format("Unexpected token (%s), expected %s",
p.getCurrentToken(), expToken);
if (msg0 != null) {
msg = msg + ": "+msg0;
}
return JsonMappingException.from(p, msg);
}
/**
* Helper method for constructing exception to indicate that given
* type id (parsed from JSON) could not be converted to a Java type.
*/
@Deprecated // since 2.5, use overloaded variant
public JsonMappingException unknownTypeException(JavaType type, String id) {
return JsonMappingException.from(_parser, "Could not resolve type id '"+id+"' into a subtype of "+
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>serializer != null && _serializer != ser) {
throw new IllegalStateException("Can not override serializer");
}
_serializer = ser;
}
/**
* Method called to assign null value serializer for property
*
* @since 2.0
*/
public void assignNullSerializer(JsonSerializer<Object> nullSer) {
// may need to disable check in future?
if (_nullSerializer != null && _nullSerializer != nullSer) {
throw new IllegalStateException("Can not override null serializer");
}
_nullSerializer = nullSer;
}
/**
* Method called create an instance that handles details of unwrapping
* contained value.
*/
public BeanPropertyWriter unwrappingWriter(NameTransformer unwrapper) {
return new UnwrappingBeanPropertyWriter(this, unwrapper);
}
/**
* Method called to define type to consider as "non-trivial" basetype,
* needed for dynamic serialization resolution for complex (usually container)
* types
*/
public void setNonTrivialBaseType(JavaType t) {
_nonTrivialBaseType = t;
}
/*
/**********************************************************
/* JDK Serializability
/**********************************************************
*/
/* Ideally would not require mutable state, and instead would re-create with
* final settings. However, as things are, with sub-types and all, simplest
* to just change Field/Method value directly.
*/
Object readResolve() {
if (_member instanceof AnnotatedField) {
_accessorMethod = null;
_field = (Field) _member.getMember();
} else if (_member instanceof AnnotatedMethod) {
_accessorMethod = (Method) _member.getMember();
_field = null;
}
if (_serializer == null) {
_dynamicSerializers = PropertySerializerMap.emptyForProperties();
}
return this;
}
/*
/**********************************************************
/* BeanProperty impl
/**********************************************************
*/
// Note: also part of 'PropertyWriter'
@Override public String getName() { return _name.getValue(); }
// Note: also part of 'PropertyWriter'
@Override public PropertyName getFullName() { // !!! TODO: impl properly
return new PropertyName(_name.getValue());
}
@Override public JavaType getType() { return _declaredType; }
@Override public PropertyName getWrapperName() { return _wrapperName; }
@Override public boolean isRequired() { return _metadata.isRequired(); }
@Override public PropertyMetadata getMetadata() { return _metadata; }
// Note: also part of 'PropertyWriter'
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return (_member == null) ? null : _member.getAnnotation(acls);
}
// Note: also part of 'PropertyWriter'
@Override
public <A extends Annotation> A getContextAnnotation(Class<A> acls) {
return (_contextAnnotations == null) ? null : _contextAnnotations.get(acls);
}
@Override
public JsonFormat.Value findFormatOverrides(AnnotationIntrospector intr) {
JsonFormat.Value f = _format;
if (f == null) { // not yet looked up, do that
f = ((intr == null) || (_member == null)) ? null
: intr.findFormat(_member);
_format = (f == null) ? NO_FORMAT : f;
}
return (f == NO_FORMAT) ? null : f;
}
@
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>Node, SerializerProvider provider)
throws JsonMappingException
{
JavaType propType = getSerializationType();
// 03-Dec-2010, tatu: SchemaAware REALLY should use JavaType, but alas it doesn't...
Type hint = (propType == null) ? getGenericPropertyType() : propType.getRawClass();
JsonNode schemaNode;
// Maybe it already has annotated/statically configured serializer?
JsonSerializer<Object> ser = getSerializer();
if (ser == null) { // nope
ser = provider.findValueSerializer(getType(), this);
}
boolean isOptional = !isRequired();
if (ser instanceof SchemaAware) {
schemaNode = ((SchemaAware) ser).getSchema(provider, hint, isOptional) ;
} else {
schemaNode = com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode();
}
_depositSchemaProperty(propertiesNode, schemaNode);
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
protected JsonSerializer<Object> _findAndAddDynamic(PropertySerializerMap map,
Class<?> type, SerializerProvider provider) throws JsonMappingException
{
PropertySerializerMap.SerializerAndMapResult result;
if (_nonTrivialBaseType != null) {
JavaType t = provider.constructSpecializedType(_nonTrivialBaseType, type);
result = map.findAndAddPrimarySerializer(t, provider, this);
} else {
result = map.findAndAddPrimarySerializer(type, provider, this);
}
// did we get a new map of serializers? If so, start using it
if (map != result.map) {
_dynamicSerializers = result.map;
}
return result.serializer;
}
/**
* Method that can be used to access value of the property this
* Object describes, from given bean instance.
*<p>
* Note: method is final as it should not need to be overridden -- rather,
* calling method(s) ({@link #serializeAsField}) should be overridden
* to change the behavior
*/
public final Object get(Object bean) throws Exception {
return (_accessorMethod == null) ? _field.get(bean) : _accessorMethod.invoke(bean);
}
/**
* Method called to handle a direct self-reference through this property.
* Method can choose to indicate an error by throwing {@link JsonMappingException};
* fully handle serialization (and return true); or indicate that it should be
* serialized normally (return false).
*<p>
* Default implementation will throw {@link JsonMappingException} if
* {@link SerializationFeature#FAIL_ON_SELF_REFERENCES} is enabled;
* or return <code>false</code> if it is disabled.
*
* @return True if method fully handled self-referential value; false if not (caller
* is to handle it) or {@link JsonMappingException} if there is no way handle it
*/
protected boolean _handleSelfReference(Object bean, JsonGenerator gen, SerializerProvider prov, JsonSerializer<?> ser)
throws JsonMappingException {
if (prov.isEnabled(SerializationFeature.FAIL_ON_SELF_REFERENCES)
&& !ser.usesObjectId()) {
// 05-Feb-2013, tatu: Usually a problem, but NOT if we are handling
// object id; this may be the case for BeanSerializers at least.
// 1
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> }
@JacksonStdImpl
public static class ShortDeserializer
extends PrimitiveOrWrapperDeserializer<Short>
{
private static final long serialVersionUID = 1L;
final static ShortDeserializer primitiveInstance = new ShortDeserializer(Short.TYPE, Short.valueOf((short)0));
final static ShortDeserializer wrapperInstance = new ShortDeserializer(Short.class, null);
public ShortDeserializer(Class<Short> cls, Short nvl)
{
super(cls, nvl);
}
@Override
public Short deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
return _parseShort(jp, ctxt);
}
}
@JacksonStdImpl
public static class CharacterDeserializer
extends PrimitiveOrWrapperDeserializer<Character>
{
private static final long serialVersionUID = 1L;
final static CharacterDeserializer primitiveInstance = new CharacterDeserializer(Character.TYPE, '\0');
final static CharacterDeserializer wrapperInstance = new CharacterDeserializer(Character.class, null);
public CharacterDeserializer(Class<Character> cls, Character nvl)
{
super(cls, nvl);
}
@Override
public Character deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_NUMBER_INT: // ok iff ascii value
int value = p.getIntValue();
if (value >= 0 && value <= 0xFFFF) {
return Character.valueOf((char) value);
}
break;
case JsonTokenId.ID_STRING: // this is the usual type
// But does it have to be exactly one char?
String text = p.getText();
if (text.length() == 1) {
return Character.valueOf(text.charAt(0));
}
// actually, empty should become null?
if (text.length() == 0) {
return (Character) getEmptyValue(ctxt);
}
break;
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Character C = deserialize(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single '" + _valueClass.getName() + "' value but there was more than a single value in the array"
);
}
return C;
}
}
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
}
@JacksonStdImpl
public final static class IntegerDeserializer
extends PrimitiveOrWrapperDeserializer<Integer>
{
private static final long serialVersionUID = 1L;
final static IntegerDeserializer primitiveInstance = new IntegerDeserializer(Integer.TYPE, Integer.valueOf(0));
final static IntegerDeserializer wrapperInstance = new IntegerDeserializer(Integer.class, null);
public IntegerDeserializer(Class<Integer> cls, Integer nvl) {
super(cls, nvl);
}
// since 2.6, slightly faster lookups for this very common type
@Override
public boolean isCachable() { return true; }
@Override
public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
if (p.hasToken(JsonToken.VALUE_NUMBER_INT)) {
return p.getIntValue();
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> return _parseInteger(p, ctxt);
}
// 1.6: since we can never have type info ("natural type"; String, Boolean, Integer, Double):
// (is it an error to even call this version?)
@Override
public Integer deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
if (p.hasToken(JsonToken.VALUE_NUMBER_INT)) {
return p.getIntValue();
}
return _parseInteger(p, ctxt);
}
}
@JacksonStdImpl
public final static class LongDeserializer
extends PrimitiveOrWrapperDeserializer<Long>
{
private static final long serialVersionUID = 1L;
final static LongDeserializer primitiveInstance = new LongDeserializer(Long.TYPE, Long.valueOf(0L));
final static LongDeserializer wrapperInstance = new LongDeserializer(Long.class, null);
public LongDeserializer(Class<Long> cls, Long nvl) {
super(cls, nvl);
}
// since 2.6, slightly faster lookups for this very common type
@Override
public boolean isCachable() { return true; }
@Override
public Long deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
if (p.hasToken(JsonToken.VALUE_NUMBER_INT)) {
return p.getLongValue();
}
return _parseLong(p, ctxt);
}
}
@JacksonStdImpl
public static class FloatDeserializer
extends PrimitiveOrWrapperDeserializer<Float>
{
private static final long serialVersionUID = 1L;
final static FloatDeserializer primitiveInstance = new FloatDeserializer(Float.TYPE, 0.f);
final static FloatDeserializer wrapperInstance = new FloatDeserializer(Float.class, null);
public FloatDeserializer(Class<Float> cls, Float nvl) {
super(cls, nvl);
}
@Override
public Float deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
return _parseFloat(p, ctxt);
}
}
@JacksonStdImpl
public static class DoubleDeserializer
extends PrimitiveOrWrapperDeserializer<Double>
{
private static final long serialVersionUID = 1L;
final static DoubleDeserializer primitiveInstance = new DoubleDeserializer(Double.TYPE, 0.d);
final static DoubleDeserializer wrapperInstance = new DoubleDeserializer(Double.class, null);
public DoubleDeserializer(Class<Double> cls, Double nvl) {
super(cls, nvl);
}
@Override
public Double deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return _parseDouble(jp, ctxt);
}
// 1.6: since we can never have type info ("natural type"; String, Boolean, Integer, Double):
// (is it an error to even call this version?)
@Override
public Double deserializeWithType(JsonParser jp, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
return _parseDouble(jp, ctxt);
}
}
/**
* For type <code>Number.class</code>, we can just rely on type
* mappings that plain {@link JsonParser#getNumberValue} returns.
*<p>
* Since 1.5, there is one additional complication: some numeric
* types (specifically, int/Integer and double/Double) are "non-typed";
* meaning that they will NEVER be output with type information.
* But other numeric types may need such type information.
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>
* This is why {@link #deserializeWithType} must be overridden.
*/
@SuppressWarnings("serial")
@JacksonStdImpl
public static class NumberDeserializer
extends StdScalarDeserializer<Object>
{
public final static NumberDeserializer instance = new NumberDeserializer();
public NumberDeserializer() {
super(Number.class);
}
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_NUMBER_INT:
if (ctxt.hasSomeOfFeatures(F_MASK_INT_COERCIONS)) {
return _coerceIntegral(p, ctxt);
}
return p.getNumberValue();
case JsonTokenId.ID_NUMBER_FLOAT:
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
return p.getDecimalValue();
}
return Double.valueOf(p.getDoubleValue());
case JsonTokenId.ID_STRING:
/* Textual values are more difficult... not parsing itself, but figuring
* out 'minimal' type to use
*/
String text = p.getText().trim();
if (text.length() == 0) {
return getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return getNullValue(ctxt);
}
if (_isPosInf(text)) {
return Double.POSITIVE_INFINITY;
}
if (_isNegInf(text)) {
return Double.NEGATIVE_INFINITY;
}
if (_isNaN(text)) {
return Double.NaN;
}
try {
if (!_isIntNumber(text)) {
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
return new BigDecimal(text);
}
return new Double(text);
}
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS)) {
return new BigInteger(text);
}
long value = Long.parseLong(text);
if (!ctxt.isEnabled(DeserializationFeature.USE_LONG_FOR_INTS)) {
if (value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE) {
return Integer.valueOf((int) value);
}
}
return Long.valueOf(value);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid number");
}
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Object value = deserialize(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single '" + _valueClass.getName() + "' value but there was more than a single value in the array"
);
}
return value;
}
break;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
/**
* As mentioned in class Javadoc, there is additional complexity in
* handling potentially mixed type information here. Because of this,
* we must actually check for "raw" integers and doubles first, before
* calling type deserializer.
*/
@Override
public Object deserializeWithType
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>(JsonParser jp, DeserializationContext ctxt,
TypeDeserializer typeDeserializer)
throws IOException
{
switch (jp.getCurrentTokenId()) {
case JsonTokenId.ID_NUMBER_INT:
case JsonTokenId.ID_NUMBER_FLOAT:
case JsonTokenId.ID_STRING:
// can not point to type information: hence must be non-typed (int/double)
return deserialize(jp, ctxt);
}
return typeDeserializer.deserializeTypedFromScalar(jp, ctxt);
}
}
/*
/**********************************************************
/* And then bit more complicated (but non-structured) number
/* types
/**********************************************************
*/
/**
* This is bit trickier to implement efficiently, while avoiding
* overflow problems.
*/
@SuppressWarnings("serial")
@JacksonStdImpl
public static class BigIntegerDeserializer
extends StdScalarDeserializer<BigInteger>
{
public final static BigIntegerDeserializer instance = new BigIntegerDeserializer();
public BigIntegerDeserializer() { super(BigInteger.class); }
@SuppressWarnings("incomplete-switch")
@Override
public BigInteger deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_NUMBER_INT:
switch (p.getNumberType()) {
case INT:
case LONG:
case BIG_INTEGER:
return p.getBigIntegerValue();
}
break;
case JsonTokenId.ID_NUMBER_FLOAT:
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "java.math.BigInteger");
}
return p.getDecimalValue().toBigInteger();
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final BigInteger value = deserialize(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'BigInteger' value but there was more than a single value in the array"
);
}
return value;
}
break;
case JsonTokenId.ID_STRING: // let's do implicit re-parse
String text = p.getText().trim();
if (text.length() == 0) {
return null;
}
try {
return new BigInteger(text);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid representation");
}
}
// String is ok too, can easily convert; otherwise, no can do:
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
}
@SuppressWarnings("serial")
@JacksonStdImpl
public static class BigDecimalDeserializer
extends StdScalarDeserializer<BigDecimal>
{
public final static BigDecimalDeserializer instance = new BigDecimalDeserializer();
public BigDecimalDeserializer() { super(BigDecimal.class); }
@Override
public BigDecimal deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException
{
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_NUMBER_INT:
case JsonTokenId.ID_NUMBER_FLOAT:
return p.getDecimalValue();
case JsonTokenId.ID_STRING:
String text = p.getText().trim();
if (text.length() ==
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> 0) {
return null;
}
try {
return new BigDecimal(text);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid representation");
}
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final BigDecimal value = deserialize(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'BigDecimal' value but there was more than a single value in the array"
);
}
return value;
}
break;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializable;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
/**
* Abstract base class common to all standard {@link JsonNode}
* implementations.
* The main addition here is that we declare that sub-classes must
* implement {@link JsonSerializable}.
* This simplifies object mapping aspects a bit, as no external serializers are needed.
*/
public abstract class BaseJsonNode
extends JsonNode
implements JsonSerializable
{
protected BaseJsonNode() { }
/*
/**********************************************************
/* Basic definitions for non-container types
/**********************************************************
*/
@Override
public final JsonNode findPath(String fieldName)
{
JsonNode value = findValue(fieldName);
if (value == null) {
return MissingNode.getInstance();
}
return value;
}
// Also, force (re)definition (2.7)
@Override public abstract int hashCode();
/*
/**********************************************************
/* Support for traversal-as-stream
/**********************************************************
*/
@Override
public JsonParser traverse() {
return new TreeTraversingParser(this);
}
@Override
public JsonParser traverse(ObjectCodec codec) {
return new TreeTraversingParser(this, codec);
}
/**
* Method that can be used for efficient type detection
* when using stream abstraction for traversing nodes.
* Will return the first {@link JsonToken} that equivalent
* stream event would produce (for most nodes there is just
* one token but for structured/container types multiple)
*/
@Override
public abstract JsonToken asToken();
/**
* Returns code that identifies type of underlying numeric
* value, if (and only if) node is a number node.
*/
@Override
public JsonParser.NumberType numberType() {
// most types non-numeric, so:
return null;
}
/*
/**********************************************************
/* JsonSerializable
/**********************************************************
*/
/**
* Method called to serialize node instances using given generator.
*/
@Override
public abstract void serialize(JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException;
/**
* Type information is needed, even if JsonNode instances are "plain" JSON,
* since they may be mixed with other types.
*/
@Override
public abstract void serializeWithType(JsonGenerator jgen, SerializerProvider provider,
TypeSerializer typeSer)
throws IOException, JsonProcessingException;
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>4, tatu: To fix [databind#408], must distinguish between
// internal and external properties
// TODO: but does it need to be injected in external case? Why not?
&& !_usesExternalId()
&& p.getCurrentToken() == JsonToken.START_OBJECT) {
// but what if there's nowhere to add it in? Error? Or skip? For now, skip.
TokenBuffer tb = new TokenBuffer(null, false);
tb.writeStartObject(); // recreate START_OBJECT
tb.writeFieldName(_typePropertyName);
tb.writeString(typeId);
p = JsonParserSequence.createFlattened(tb.asParser(p), p);
p.nextToken();
}
Object value = deser.deserialize(p, ctxt);
// And then need the closing END_ARRAY
if (hadStartArray && p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"expected closing END_ARRAY after type information and deserialized value");
}
return value;
}
protected String _locateTypeId(JsonParser jp, DeserializationContext ctxt) throws IOException
{
if (!jp.isExpectedStartArrayToken()) {
// Need to allow even more customized handling, if something unexpected seen...
// but should there be a way to limit this to likely success cases?
if (_defaultImpl != null) {
return _idResolver.idFromBaseType();
}
throw ctxt.wrongTokenException(jp, JsonToken.START_ARRAY, "need JSON Array to contain As.WRAPPER_ARRAY type information for class "+baseTypeName());
}
// And then type id as a String
JsonToken t = jp.nextToken();
if (t == JsonToken.VALUE_STRING) {
String result = jp.getText();
jp.nextToken();
return result;
}
if (_defaultImpl != null) {
return _idResolver.idFromBaseType();
}
throw ctxt.wrongTokenException(jp, JsonToken.VALUE_STRING, "need JSON String that contains type id (for subtype of "+baseTypeName()+")");
}
/**
* @since 2.5
*/
protected boolean _usesExternalId() {
return false;
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.util.HashSet;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Variant of {@link BeanDeserializer} used for handling deserialization
* of POJOs when serialized as JSON Arrays, instead of JSON Objects.
*
* @since 2.1
*/
public class BeanAsArrayDeserializer
extends BeanDeserializerBase
{
private static final long serialVersionUID = 1L;
/**
* Deserializer we delegate operations that we can not handle.
*/
protected final BeanDeserializerBase _delegate;
/**
* Properties in order expected to be found in JSON array.
*/
protected final SettableBeanProperty[] _orderedProperties;
/*
/**********************************************************
/* Life-cycle, construction, initialization
/**********************************************************
*/
/**
* Main constructor used both for creating new instances (by
* {@link BeanDeserializer#asArrayDeserializer}) and for
* creating copies with different delegate.
*/
public BeanAsArrayDeserializer(BeanDeserializerBase delegate,
SettableBeanProperty[] ordered)
{
super(delegate);
_delegate = delegate;
_orderedProperties = ordered;
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper)
{
/* We can't do much about this; could either replace _delegate
* with unwrapping instance, or just replace this one. Latter seems
* more sensible.
*/
return _delegate.unwrappingDeserializer(unwrapper);
}
@Override
public BeanAsArrayDeserializer withObjectIdReader(ObjectIdReader oir) {
return new BeanAsArrayDeserializer(_delegate.withObjectIdReader(oir),
_orderedProperties);
}
@Override
public BeanAsArrayDeserializer withIgnorableProperties(HashSet<String> ignorableProps) {
return new BeanAsArrayDeserializer(_delegate.withIgnorableProperties(ignorableProps),
_orderedProperties);
}
@Override
protected BeanDeserializerBase asArrayDeserializer() {
return this;
}
/*
/**********************************************************
/* JsonDeserializer implementation
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException
{
// Let's delegate just in case we got a JSON Object (could error out, alternatively?)
if (!p.isExpectedStartArrayToken()) {
return _deserializeFromNonArray(p, ctxt);
}
if (!_vanillaProcessing) {
return _deserializeNonVanilla(p, ctxt);
}
final Object bean = _valueInstantiator.createUsingDefault(ctxt);
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
final SettableBeanProperty[] props = _orderedProperties;
int i = 0;
final int propCount = props.length;
while (true) {
if (p.nextToken() == JsonToken.END_ARRAY) {
return bean;
}
if (i == propCount) {
break;
}
SettableBeanProperty prop = props[i];
if (prop != null) { // normal case
try {
prop.deserializeAndSet(p, ctxt, bean);
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>
} catch (Exception e) {
wrapAndThrow(e, bean, prop.getName(), ctxt);
}
} else { // just skip?
p.skipChildren();
}
++i;
}
// Ok; extra fields? Let's fail, unless ignoring extra props is fine
if (!_ignoreAllUnknown) {
throw ctxt.mappingException("Unexpected JSON values; expected at most %d properties (in JSON Array)",
propCount);
}
// otherwise, skip until end
while (p.nextToken() != JsonToken.END_ARRAY) {
p.skipChildren();
}
return bean;
}
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt, Object bean)
throws IOException
{
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
/* No good way to verify that we have an array... although could I guess
* check via JsonParser. So let's assume everything is working fine, for now.
*/
if (_injectables != null) {
injectValues(ctxt, bean);
}
final SettableBeanProperty[] props = _orderedProperties;
int i = 0;
final int propCount = props.length;
while (true) {
if (p.nextToken() == JsonToken.END_ARRAY) {
return bean;
}
if (i == propCount) {
break;
}
SettableBeanProperty prop = props[i];
if (prop != null) { // normal case
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, prop.getName(), ctxt);
}
} else { // just skip?
p.skipChildren();
}
++i;
}
// Ok; extra fields? Let's fail, unless ignoring extra props is fine
if (!_ignoreAllUnknown) {
throw ctxt.mappingException("Unexpected JSON values; expected at most %d properties (in JSON Array)",
propCount);
}
// otherwise, skip until end
while (p.nextToken() != JsonToken.END_ARRAY) {
p.skipChildren();
}
return bean;
}
// needed since 2.1
@Override
public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt)
throws IOException
{
return _deserializeFromNonArray(p, ctxt);
}
/*
/**********************************************************
/* Helper methods, non-standard creation
/**********************************************************
*/
/**
* Alternate deserialization method that has to check many more configuration
* aspects than the "vanilla" processing.
*/
protected Object _deserializeNonVanilla(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (_nonStandardCreation) {
return _deserializeWithCreator(p, ctxt);
}
final Object bean = _valueInstantiator.createUsingDefault(ctxt);
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
if (_injectables != null) {
injectValues(ctxt, bean);
}
Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
final SettableBeanProperty[] props = _orderedProperties;
int i = 0;
final int propCount = props.length;
while (true) {
if (p.nextToken() == JsonToken.END
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>_ARRAY) {
return bean;
}
if (i == propCount) {
break;
}
SettableBeanProperty prop = props[i];
++i;
if (prop != null) { // normal case
if (activeView == null || prop.visibleInView(activeView)) {
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, prop.getName(), ctxt);
}
continue;
}
}
// otherwise, skip it (view-filtered, no prop etc)
p.skipChildren();
}
// Ok; extra fields? Let's fail, unless ignoring extra props is fine
if (!_ignoreAllUnknown) {
throw ctxt.mappingException("Unexpected JSON values; expected at most %d properties (in JSON Array)",
propCount);
}
// otherwise, skip until end
while (p.nextToken() != JsonToken.END_ARRAY) {
p.skipChildren();
}
return bean;
}
protected Object _deserializeWithCreator(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (_delegateDeserializer != null) {
return _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.deserialize(p, ctxt));
}
if (_propertyBasedCreator != null) {
return _deserializeUsingPropertyBased(p, ctxt);
}
// should only occur for abstract types...
if (_beanType.isAbstract()) {
throw JsonMappingException.from(p, "Can not instantiate abstract type "+_beanType
+" (need to add/enable type information?)");
}
throw JsonMappingException.from(p, "No suitable constructor found for type "
+_beanType+": can not instantiate from JSON object (need to add/enable type information?)");
}
/**
* Method called to deserialize bean using "property-based creator":
* this means that a non-default constructor or factory method is
* called, and then possibly other setters. The trick is that
* values for creator method need to be buffered, first; and
* due to non-guaranteed ordering possibly some other properties
* as well.
*/
@Override
protected final Object _deserializeUsingPropertyBased(final JsonParser p, final DeserializationContext ctxt)
throws IOException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
final SettableBeanProperty[] props = _orderedProperties;
final int propCount = props.length;
int i = 0;
Object bean = null;
for (; p.nextToken() != JsonToken.END_ARRAY; ++i) {
SettableBeanProperty prop = (i < propCount) ? props[i] : null;
if (prop == null) { // we get null if there are extra elements; maybe otherwise too?
p.skipChildren();
continue;
}
// if we have already constructed POJO, things are simple:
if (bean != null) {
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, prop.getName(), ctxt);
}
continue;
}
final String propName = prop.getName();
// if not yet, maybe we got a creator property?
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
/**
* Intermediate base deserializer class that adds more shared accessor
* so that other classes can access information about contained (value)
* types
*/
@SuppressWarnings("serial")
public abstract class ContainerDeserializerBase<T>
extends StdDeserializer<T>
{
protected ContainerDeserializerBase(JavaType selfType) {
super(selfType);
}
/**
* @deprecated Since 2.3 use one that takes {@link JavaType}
*/
@Deprecated
protected ContainerDeserializerBase(Class<?> selfType) {
super(selfType);
}
/*
/**********************************************************
/* Overrides
/**********************************************************
*/
@Override
public SettableBeanProperty findBackReference(String refName) {
JsonDeserializer<Object> valueDeser = getContentDeserializer();
if (valueDeser == null) {
throw new IllegalArgumentException("Can not handle managed/back reference '"+refName
+"': type: container deserializer of type "+getClass().getName()+" returned null for 'getContentDeserializer()'");
}
return valueDeser.findBackReference(refName);
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Accessor for declared type of contained value elements; either exact
* type, or one of its supertypes.
*/
public abstract JavaType getContentType();
/**
* Accesor for deserializer use for deserializing content values.
*/
public abstract JsonDeserializer<Object> getContentDeserializer();
/*
/**********************************************************
/* Shared methods for sub-classes
/**********************************************************
*/
/**
* Helper method called by various Map(-like) deserializers.
*/
protected void wrapAndThrow(Throwable t, Object ref, String key) throws IOException
{
// to handle StackOverflow:
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors and "plain" IOExceptions to be passed as is
if (t instanceof Error) {
throw (Error) t;
}
// ... except for mapping exceptions
if (t instanceof IOException && !(t instanceof JsonMappingException)) {
throw (IOException) t;
}
throw JsonMappingException.wrapWithPath(t, ref, key);
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
@SuppressWarnings("serial")
public abstract class StdScalarSerializer<T>
extends StdSerializer<T>
{
protected StdScalarSerializer(Class<T> t) {
super(t);
}
/**
* Alternate constructor that is (alas!) needed to work
* around kinks of generic type handling
*/
@SuppressWarnings("unchecked")
protected StdScalarSerializer(Class<?> t, boolean dummy) {
super((Class<T>) t);
}
/**
* Default implementation will write type prefix, call regular serialization
* method (since assumption is that value itself does not need JSON
* Array or Object start/end markers), and then write type suffix.
* This should work for most cases; some sub-classes may want to
* change this behavior.
*/
@Override
public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider provider,
TypeSerializer typeSer) throws IOException
{
typeSer.writeTypePrefixForScalar(value, jgen);
serialize(value, jgen, provider);
typeSer.writeTypeSuffixForScalar(value, jgen);
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
return createSchemaNode("string", true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
if (visitor != null) {
// 13-Sep-2013, tatu: Let's assume it's usually a String, right?
// visitor.expectAnyFormat(typeHint);
visitor.expectStringFormat(typeHint);
}
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Member;
import java.lang.reflect.Type;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
/**
* Object that represents method parameters, mostly so that associated
* annotations can be processed conveniently. Note that many of accessors
* can not return meaningful values since parameters do not have stand-alone
* JDK objects associated; so access should mostly be limited to checking
* annotation values which are properly aggregated and included.
*/
public final class AnnotatedParameter
extends AnnotatedMember
{
private static final long serialVersionUID = 1L;
/**
* Member (method, constructor) that this parameter belongs to
*/
protected final AnnotatedWithParams _owner;
/**
* JDK type of the parameter, possibly contains generic type information
*/
protected final Type _type;
/**
* Index of the parameter within argument list
*/
protected final int _index;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public AnnotatedParameter(AnnotatedWithParams owner, Type type, AnnotationMap annotations,
int index)
{
super((owner == null) ? null : owner.getContextClass(), annotations);
_owner = owner;
_type = type;
_index = index;
}
@Override
public AnnotatedParameter withAnnotations(AnnotationMap ann) {
if (ann == _annotations) {
return this;
}
return _owner.replaceParameterAnnotations(_index, ann);
}
/*
/**********************************************************
/* Annotated impl
/**********************************************************
*/
/**
* Since there is no matching JDK element, this method will
* always return null
*/
@Override
public AnnotatedElement getAnnotated() { return null; }
/**
* Returns modifiers of the constructor, as parameters do not
* have independent modifiers.
*/
@Override
public int getModifiers() { return _owner.getModifiers(); }
/**
* Parameters have no names in bytecode (unlike in source code),
* will always return empty String ("").
*/
@Override
public String getName() { return ""; }
/**
* Accessor for annotations; all annotations associated with parameters
* are properly passed and accessible.
*/
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls)
{
return (_annotations == null) ? null : _annotations.get(acls);
}
@Override
public Type getGenericType() {
return _type;
}
@Override
public Class<?> getRawType()
{
if (_type instanceof Class<?>) {
return (Class<?>) _type;
}
// 14-Mar-2011, tatu: Not optimal, but has to do for now...
JavaType t = TypeFactory.defaultInstance().constructType(_type);
return t.getRawClass();
}
/*
/**********************************************************
/* AnnotatedMember extras
/**********************************************************
*/
@Override
public Class<?> getDeclaringClass() {
return _owner.getDeclaringClass();
}
@Override
public Member getMember() {
/* This is bit tricky: since there is no JDK equivalent; can either
* return null or owner... let's do latter, for now.
*/
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Numeric node that contains simple 64-bit integer values.
*/
public class BigIntegerNode
extends NumericNode
{
private final static BigInteger MIN_INTEGER = BigInteger.valueOf(Integer.MIN_VALUE);
private final static BigInteger MAX_INTEGER = BigInteger.valueOf(Integer.MAX_VALUE);
private final static BigInteger MIN_LONG = BigInteger.valueOf(Long.MIN_VALUE);
private final static BigInteger MAX_LONG = BigInteger.valueOf(Long.MAX_VALUE);
final protected BigInteger _value;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
public BigIntegerNode(BigInteger v) { _value = v; }
public static BigIntegerNode valueOf(BigInteger v) { return new BigIntegerNode(v); }
/*
/**********************************************************
/* Overrridden JsonNode methods
/**********************************************************
*/
@Override
public JsonToken asToken() { return JsonToken.VALUE_NUMBER_INT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.BIG_INTEGER; }
@Override
public boolean isIntegralNumber() { return true; }
@Override
public boolean isBigInteger() { return true; }
@Override public boolean canConvertToInt() {
return (_value.compareTo(MIN_INTEGER) >= 0) && (_value.compareTo(MAX_INTEGER) <= 0);
}
@Override public boolean canConvertToLong() {
return (_value.compareTo(MIN_LONG) >= 0) && (_value.compareTo(MAX_LONG) <= 0);
}
@Override
public Number numberValue() {
return _value;
}
@Override
public short shortValue() { return _value.shortValue(); }
@Override
public int intValue() { return _value.intValue(); }
@Override
public long longValue() { return _value.longValue(); }
@Override
public BigInteger bigIntegerValue() { return _value; }
@Override
public float floatValue() { return _value.floatValue(); }
@Override
public double doubleValue() { return _value.doubleValue(); }
@Override
public BigDecimal decimalValue() { return new BigDecimal(_value); }
/*
/**********************************************************
/* General type coercions
/**********************************************************
*/
@Override
public String asText() {
return _value.toString();
}
@Override
public boolean asBoolean(boolean defaultValue) {
return !BigInteger.ZERO.equals(_value);
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.writeNumber(_value);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (!(o instanceof BigIntegerNode)) {
return false;
}
return ((BigIntegerNode) o)._value.equals(_value);
}
@Override
public int hashCode() {
return _value.hashCode();
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.jsontype.impl;
import java.io.IOException;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.util.JsonParserSequence;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
import com.fasterxml.jackson.databind.util.TokenBuffer;
/**
* Type deserializer used with {@link As#PROPERTY}
* inclusion mechanism.
* Uses regular form (additional key/value entry before actual data)
* when typed object is expressed as JSON Object; otherwise behaves similar to how
* {@link As#WRAPPER_ARRAY} works.
* Latter is used if JSON representation is polymorphic
*/
public class AsPropertyTypeDeserializer extends AsArrayTypeDeserializer
{
private static final long serialVersionUID = 1L;
protected final As _inclusion;
public AsPropertyTypeDeserializer(JavaType bt, TypeIdResolver idRes,
String typePropertyName, boolean typeIdVisible, Class<?> defaultImpl)
{
this(bt, idRes, typePropertyName, typeIdVisible, defaultImpl, As.PROPERTY);
}
public AsPropertyTypeDeserializer(JavaType bt, TypeIdResolver idRes,
String typePropertyName, boolean typeIdVisible, Class<?> defaultImpl,
As inclusion)
{
super(bt, idRes, typePropertyName, typeIdVisible, defaultImpl);
_inclusion = inclusion;
}
public AsPropertyTypeDeserializer(AsPropertyTypeDeserializer src, BeanProperty property) {
super(src, property);
_inclusion = src._inclusion;
}
@Override
public TypeDeserializer forProperty(BeanProperty prop) {
return (prop == _property) ? this : new AsPropertyTypeDeserializer(this, prop);
}
@Override
public As getTypeInclusion() { return _inclusion; }
/**
* This is the trickiest thing to handle, since property we are looking
* for may be anywhere...
*/
@Override
@SuppressWarnings("resource")
public Object deserializeTypedFromObject(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// 02-Aug-2013, tatu: May need to use native type ids
if (jp.canReadTypeId()) {
Object typeId = jp.getTypeId();
if (typeId != null) {
return _deserializeWithNativeTypeId(jp, ctxt, typeId);
}
}
// but first, sanity check to ensure we have START_OBJECT or FIELD_NAME
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.START_OBJECT) {
t = jp.nextToken();
} else if (t == JsonToken.START_ARRAY) {
/* This is most likely due to the fact that not all Java types are
* serialized as JSON Objects; so if "as-property" inclusion is requested,
* serialization of things like Lists must be instead handled as if
* "as-wrapper-array" was requested.
* But this can also be due to some custom handling: so, if "defaultImpl"
* is defined, it will be asked to handle this case.
*/
return _deserializeTypedUsingDefaultImpl(jp, ctxt, null);
} else if (t != JsonToken.FIELD_NAME) {
return _deserializeTypedUsing
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>DefaultImpl(jp, ctxt, null);
}
// Ok, let's try to find the property. But first, need token buffer...
TokenBuffer tb = null;
for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) {
String name = jp.getCurrentName();
jp.nextToken(); // to point to the value
if (_typePropertyName.equals(name)) { // gotcha!
return _deserializeTypedForId(jp, ctxt, tb);
}
if (tb == null) {
tb = new TokenBuffer(jp, ctxt);
}
tb.writeFieldName(name);
tb.copyCurrentStructure(jp);
}
return _deserializeTypedUsingDefaultImpl(jp, ctxt, tb);
}
@SuppressWarnings("resource")
protected Object _deserializeTypedForId(JsonParser jp, DeserializationContext ctxt, TokenBuffer tb) throws IOException
{
String typeId = jp.getText();
JsonDeserializer<Object> deser = _findDeserializer(ctxt, typeId);
if (_typeIdVisible) { // need to merge id back in JSON input?
if (tb == null) {
tb = new TokenBuffer(jp, ctxt);
}
tb.writeFieldName(jp.getCurrentName());
tb.writeString(typeId);
}
if (tb != null) { // need to put back skipped properties?
jp = JsonParserSequence.createFlattened(tb.asParser(jp), jp);
}
// Must point to the next value; tb had no current, jp pointed to VALUE_STRING:
jp.nextToken(); // to skip past String value
// deserializer should take care of closing END_OBJECT as well
return deser.deserialize(jp, ctxt);
}
// off-lined to keep main method lean and mean...
@SuppressWarnings("resource")
protected Object _deserializeTypedUsingDefaultImpl(JsonParser jp, DeserializationContext ctxt, TokenBuffer tb) throws IOException
{
// As per [JACKSON-614], may have default implementation to use
JsonDeserializer<Object> deser = _findDefaultImplDeserializer(ctxt);
if (deser != null) {
if (tb != null) {
tb.writeEndObject();
jp = tb.asParser(jp);
// must move to point to the first token:
jp.nextToken();
}
return deser.deserialize(jp, ctxt);
}
// or, perhaps we just bumped into a "natural" value (boolean/int/double/String)?
Object result = TypeDeserializer.deserializeIfNatural(jp, ctxt, _baseType);
if (result != null) {
return result;
}
// or, something for which "as-property" won't work, changed into "wrapper-array" type:
if (jp.getCurrentToken() == JsonToken.START_ARRAY) {
return super.deserializeTypedFromAny(jp, ctxt);
}
throw ctxt.wrongTokenException(jp, JsonToken.FIELD_NAME,
"missing property '"+_typePropertyName+"' that is to contain type id (for class "+baseTypeName()+")");
}
/* As per [JACKSON-352], also need to re-route "unknown" version. Need to think
* this through bit more in future, but for now this does address issue and has
* no negative side effects (at least within existing unit test suite).
*/
@Override
public Object deserializeTypedFromAny(JsonParser jp, DeserializationContext ctxt
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>) throws IOException {
/* [JACKSON-387]: Sometimes, however, we get an array wrapper; specifically
* when an array or list has been serialized with type information.
*/
if (jp.getCurrentToken() == JsonToken.START_ARRAY) {
return super.deserializeTypedFromArray(jp, ctxt);
}
return deserializeTypedFromObject(jp, ctxt);
}
// These are fine from base class:
//public Object deserializeTypedFromArray(JsonParser jp, DeserializationContext ctxt)
//public Object deserializeTypedFromScalar(JsonParser jp, DeserializationContext ctxt)
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonschema.SchemaAware;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.PropertyFilter;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.Converter;
/**
* Base class used by all standard serializers, and can also
* be used for custom serializers (in fact, this is the recommended
* base class to use).
* Provides convenience methods for implementing {@link SchemaAware}
*/
public abstract class StdSerializer<T>
extends JsonSerializer<T>
implements JsonFormatVisitable, SchemaAware, java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Nominal type supported, usually declared type of
* property for which serializer is used.
*/
protected final Class<T> _handledType;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
protected StdSerializer(Class<T> t) {
_handledType = t;
}
@SuppressWarnings("unchecked")
protected StdSerializer(JavaType type) {
_handledType = (Class<T>) type.getRawClass();
}
/**
* Alternate constructor that is (alas!) needed to work
* around kinks of generic type handling
*/
@SuppressWarnings("unchecked")
protected StdSerializer(Class<?> t, boolean dummy) {
_handledType = (Class<T>) t;
}
/**
* @since 2.6
*/
@SuppressWarnings("unchecked")
protected StdSerializer(StdSerializer<?> src) {
_handledType = (Class<T>) src._handledType;
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public Class<T> handledType() { return _handledType; }
/*
/**********************************************************
/* Serialization
/**********************************************************
*/
@Override
public abstract void serialize(T value, JsonGenerator gen, SerializerProvider provider)
throws IOException;
/*
/**********************************************************
/* Helper methods for JSON Schema generation
/**********************************************************
*/
/**
* Default implementation simply claims type is "string"; usually
* overriden by custom serializers.
*/
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
return createSchemaNode("string");
}
/**
* Default implementation simply claims type is "string"; usually
* overriden by custom serializers.
*/
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint, boolean isOptional)
throws JsonMappingException
{
ObjectNode schema = (ObjectNode) get
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>Schema(provider, typeHint);
if (!isOptional) {
schema.put("required", !isOptional);
}
return schema;
}
protected ObjectNode createObjectNode() {
return JsonNodeFactory.instance.objectNode();
}
protected ObjectNode createSchemaNode(String type)
{
ObjectNode schema = createObjectNode();
schema.put("type", type);
return schema;
}
protected ObjectNode createSchemaNode(String type, boolean isOptional)
{
ObjectNode schema = createSchemaNode(type);
// as per [JACKSON-563]. Note that 'required' defaults to false
if (!isOptional) {
schema.put("required", !isOptional);
}
return schema;
}
/**
* Default implementation specifies no format. This behavior is usually
* overriden by custom serializers.
*/
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
visitor.expectAnyFormat(typeHint);
}
/*
/**********************************************************
/* Helper methods for exception handling
/**********************************************************
*/
/**
* Method that will modify caught exception (passed in as argument)
* as necessary to include reference information, and to ensure it
* is a subtype of {@link IOException}, or an unchecked exception.
*<p>
* Rules for wrapping and unwrapping are bit complicated; essentially:
*<ul>
* <li>Errors are to be passed as is (if uncovered via unwrapping)
* <li>"Plain" IOExceptions (ones that are not of type
* {@link JsonMappingException} are to be passed as is
*</ul>
*/
public void wrapAndThrow(SerializerProvider provider,
Throwable t, Object bean, String fieldName)
throws IOException
{
/* 05-Mar-2009, tatu: But one nasty edge is when we get
* StackOverflow: usually due to infinite loop. But that
* usually gets hidden within an InvocationTargetException...
*/
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors and "plain" IOExceptions to be passed as is
if (t instanceof Error) {
throw (Error) t;
}
// Ditto for IOExceptions... except for mapping exceptions!
boolean wrap = (provider == null) || provider.isEnabled(SerializationFeature.WRAP_EXCEPTIONS);
if (t instanceof IOException) {
if (!wrap || !(t instanceof JsonMappingException)) {
throw (IOException) t;
}
} else if (!wrap) { // [JACKSON-407] -- allow disabling wrapping for unchecked exceptions
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
}
// [JACKSON-55] Need to add reference information
throw JsonMappingException.wrapWithPath(t, bean, fieldName);
}
public void wrapAndThrow(SerializerProvider provider,
Throwable t, Object bean, int index)
throws IOException
{
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors are to be passed as is
if (t instanceof Error) {
throw (Error) t;
}
// Ditto for IOExceptions... except for mapping exceptions!
boolean wrap = (provider == null) || provider.
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>isEnabled(SerializationFeature.WRAP_EXCEPTIONS);
if (t instanceof IOException) {
if (!wrap || !(t instanceof JsonMappingException)) {
throw (IOException) t;
}
} else if (!wrap) { // [JACKSON-407] -- allow disabling wrapping for unchecked exceptions
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
}
// [JACKSON-55] Need to add reference information
throw JsonMappingException.wrapWithPath(t, bean, index);
}
/*
/**********************************************************
/* Helper methods, other
/**********************************************************
*/
/**
* Method that can be called to determine if given serializer is the default
* serializer Jackson uses; as opposed to a custom serializer installed by
* a module or calling application. Determination is done using
* {@link JacksonStdImpl} annotation on serializer class.
*/
protected boolean isDefaultSerializer(JsonSerializer<?> serializer) {
return ClassUtil.isJacksonStdImpl(serializer);
}
/**
* Helper method that can be used to see if specified property has annotation
* indicating that a converter is to be used for contained values (contents
* of structured types; array/List/Map values)
*
* @param existingSerializer (optional) configured content
* serializer if one already exists.
*
* @since 2.2
*/
protected JsonSerializer<?> findConvertingContentSerializer(SerializerProvider provider,
BeanProperty prop, JsonSerializer<?> existingSerializer)
throws JsonMappingException
{
/* 19-Oct-2014, tatu: As per [databind#357], need to avoid infinite loop
* when applying contextual content converter; this is not ideal way,
* but should work for most cases.
*/
final AnnotationIntrospector intr = provider.getAnnotationIntrospector();
if (intr != null && prop != null) {
AnnotatedMember m = prop.getMember();
if (m != null) {
Object convDef = intr.findSerializationContentConverter(m);
if (convDef != null) {
Converter<Object,Object> conv = provider.converterInstance(prop.getMember(), convDef);
JavaType delegateType = conv.getOutputType(provider.getTypeFactory());
// [databind#731]: Should skip if nominally java.lang.Object
if (existingSerializer == null && !delegateType.hasRawClass(Object.class)) {
existingSerializer = provider.findValueSerializer(delegateType);
}
return new StdDelegatingSerializer(conv, delegateType, existingSerializer);
}
}
}
return existingSerializer;
}
/**
* Helper method used to locate filter that is needed, based on filter id
* this serializer was constructed with.
*
* @since 2.3
*/
protected PropertyFilter findPropertyFilter(SerializerProvider provider,
Object filterId, Object valueToFilter)
throws JsonMappingException
{
FilterProvider filters = provider.getFilterProvider();
// Not ok to miss the provider, if a filter is declared to be needed.
if (filters == null) {
throw new JsonMappingException("Can not resolve PropertyFilter with id '"+filterId+"'; no FilterProvider configured");
}
PropertyFilter filter = filters.findPropertyFilter(filterId, valueToFilter);
// But whether unknown ids are ok just depends on filter provider; if we get null that's fine
return filter;
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializable;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.util.RawValue;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
/**
* Node class that represents Arrays mapped from JSON content.
*<p>
* Note: class was <code>final</code> temporarily for Jackson 2.2.
*/
public class ArrayNode
extends ContainerNode<ArrayNode>
{
private final List<JsonNode> _children = new ArrayList<JsonNode>();
public ArrayNode(JsonNodeFactory nc) { super(nc); }
@Override
protected JsonNode _at(JsonPointer ptr) {
return get(ptr.getMatchingIndex());
}
// note: co-variant to allow caller-side type safety
@SuppressWarnings("unchecked")
@Override
public ArrayNode deepCopy()
{
ArrayNode ret = new ArrayNode(_nodeFactory);
for (JsonNode element: _children)
ret._children.add(element.deepCopy());
return ret;
}
/*
/**********************************************************
/* Overrides for JsonSerializable.Base
/**********************************************************
*/
@Override
public boolean isEmpty(SerializerProvider serializers) {
return _children.isEmpty();
}
/*
/**********************************************************
/* Implementation of core JsonNode API
/**********************************************************
*/
@Override
public JsonNodeType getNodeType() {
return JsonNodeType.ARRAY;
}
@Override public JsonToken asToken() { return JsonToken.START_ARRAY; }
@Override
public int size() {
return _children.size();
}
@Override
public Iterator<JsonNode> elements() {
return _children.iterator();
}
@Override
public JsonNode get(int index) {
if (index >= 0 && index < _children.size()) {
return _children.get(index);
}
return null;
}
@Override
public JsonNode get(String fieldName) { return null; }
@Override
public JsonNode path(String fieldName) { return MissingNode.getInstance(); }
@Override
public JsonNode path(int index) {
if (index >= 0 && index < _children.size()) {
return _children.get(index);
}
return MissingNode.getInstance();
}
@Override
public boolean equals(Comparator<JsonNode> comparator, JsonNode o)
{
if (!(o instanceof ArrayNode)) {
return false;
}
ArrayNode other = (ArrayNode) o;
final int len = _children.size();
if (other.size() != len) {
return false;
}
List<JsonNode> l1 = _children;
List<JsonNode> l2 = other._children;
for (int i = 0; i < len; ++i) {
if (comparator.compare(l1.get(i), l2.get(i)) != 0) {
return false;
}
}
return true;
}
/*
/**********************************************************
/* Public API, serialization
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>unchecked")
@Override
public Collection<Object> deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (_delegateDeserializer != null) {
return (Collection<Object>) _valueInstantiator.createUsingDelegate(ctxt,
_delegateDeserializer.deserialize(p, ctxt));
}
/* [JACKSON-620]: empty String may be ok; bit tricky to check, however, since
* there is also possibility of "auto-wrapping" of single-element arrays.
* Hence we only accept empty String here.
*/
if (p.getCurrentToken() == JsonToken.VALUE_STRING) {
String str = p.getText();
if (str.length() == 0) {
return (Collection<Object>) _valueInstantiator.createFromString(ctxt, str);
}
}
return deserialize(p, ctxt, (Collection<Object>) _valueInstantiator.createUsingDefault(ctxt));
}
@Override
public Collection<Object> deserialize(JsonParser p, DeserializationContext ctxt,
Collection<Object> result)
throws IOException
{
// Ok: must point to START_ARRAY (or equivalent)
if (!p.isExpectedStartArrayToken()) {
return handleNonArray(p, ctxt, result);
}
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(result);
JsonDeserializer<Object> valueDes = _valueDeserializer;
final TypeDeserializer typeDeser = _valueTypeDeserializer;
CollectionReferringAccumulator referringAccumulator =
(valueDes.getObjectIdReader() == null) ? null :
new CollectionReferringAccumulator(_collectionType.getContentType().getRawClass(), result);
JsonToken t;
while ((t = p.nextToken()) != JsonToken.END_ARRAY) {
try {
Object value;
if (t == JsonToken.VALUE_NULL) {
value = valueDes.getNullValue(ctxt);
} else if (typeDeser == null) {
value = valueDes.deserialize(p, ctxt);
} else {
value = valueDes.deserializeWithType(p, ctxt, typeDeser);
}
if (referringAccumulator != null) {
referringAccumulator.add(value);
} else {
result.add(value);
}
} catch (UnresolvedForwardReference reference) {
if (referringAccumulator == null) {
throw JsonMappingException
.from(p, "Unresolved forward reference but no identity info", reference);
}
Referring ref = referringAccumulator.handleUnresolvedReference(reference);
reference.getRoid().appendReferring(ref);
} catch (Exception e) {
boolean wrap = (ctxt == null) || ctxt.isEnabled(DeserializationFeature.WRAP_EXCEPTIONS);
if (!wrap && e instanceof RuntimeException) {
throw (RuntimeException)e;
}
throw JsonMappingException.wrapWithPath(e, result, result.size());
}
}
return result;
}
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt,
TypeDeserializer typeDeserializer)
throws IOException
{
// In future could check current token... for now this should be enough:
return typeDeserializer.deserializeTypedFromArray(jp, ctxt);
}
/**
* Helper method called when current token is no START_ARRAY. Will either
* throw an exception, or try to handle value as if member of implicit
* array, depending on configuration.
*/
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> protected final Collection<Object> handleNonArray(JsonParser p, DeserializationContext ctxt,
Collection<Object> result)
throws IOException
{
// [JACKSON-526]: implicit arrays from single values?
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)) {
throw ctxt.mappingException(_collectionType.getRawClass());
}
JsonDeserializer<Object> valueDes = _valueDeserializer;
final TypeDeserializer typeDeser = _valueTypeDeserializer;
JsonToken t = p.getCurrentToken();
Object value;
try {
if (t == JsonToken.VALUE_NULL) {
value = valueDes.getNullValue(ctxt);
} else if (typeDeser == null) {
value = valueDes.deserialize(p, ctxt);
} else {
value = valueDes.deserializeWithType(p, ctxt, typeDeser);
}
} catch (Exception e) {
// note: pass Object.class, not Object[].class, as we need element type for error info
throw JsonMappingException.wrapWithPath(e, Object.class, result.size());
}
result.add(value);
return result;
}
public final static class CollectionReferringAccumulator {
private final Class<?> _elementType;
private final Collection<Object> _result;
/**
* A list of {@link CollectionReferring} to maintain ordering.
*/
private List<CollectionReferring> _accumulator = new ArrayList<CollectionReferring>();
public CollectionReferringAccumulator(Class<?> elementType, Collection<Object> result) {
_elementType = elementType;
_result = result;
}
public void add(Object value)
{
if (_accumulator.isEmpty()) {
_result.add(value);
} else {
CollectionReferring ref = _accumulator.get(_accumulator.size() - 1);
ref.next.add(value);
}
}
public Referring handleUnresolvedReference(UnresolvedForwardReference reference)
{
CollectionReferring id = new CollectionReferring(this, reference, _elementType);
_accumulator.add(id);
return id;
}
public void resolveForwardReference(Object id, Object value) throws IOException
{
Iterator<CollectionReferring> iterator = _accumulator.iterator();
// Resolve ordering after resolution of an id. This mean either:
// 1- adding to the result collection in case of the first unresolved id.
// 2- merge the content of the resolved id with its previous unresolved id.
Collection<Object> previous = _result;
while (iterator.hasNext()) {
CollectionReferring ref = iterator.next();
if (ref.hasId(id)) {
iterator.remove();
previous.add(value);
previous.addAll(ref.next);
return;
}
previous = ref.next;
}
throw new IllegalArgumentException("Trying to resolve a forward reference with id [" + id
+ "] that wasn't previously seen as unresolved.");
}
}
/**
* Helper class to maintain processing order of value. The resolved
* object associated with {@link #_id} comes before the values in
* {@link #next}.
*/
private final static class CollectionReferring extends Referring {
private final CollectionReferringAccumulator _parent;
public final List<Object> next = new ArrayList<Object>();
CollectionReferring(CollectionReferringAccumulator parent,
UnresolvedForwardReference reference, Class<?> contentType)
{
super
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>Property prop = (SettableBeanProperty) _hashArea[i];
if (prop == null) {
continue;
}
if (!found) {
found = key.equals(prop.getName());
if (found) {
// need to leave a hole here
_propsInOrder[_findFromOrdered(prop)] = null;
continue;
}
}
props.add(prop);
}
if (!found) {
throw new NoSuchElementException("No entry '"+propToRm.getName()+"' found, can't remove");
}
init(props);
}
/**
* Convenience method that tries to find property with given name, and
* if it is found, call {@link SettableBeanProperty#deserializeAndSet}
* on it, and return true; or, if not found, return false.
* Note, too, that if deserialization is attempted, possible exceptions
* are wrapped if and as necessary, so caller need not handle those.
*
* @since 2.5
*/
public boolean findDeserializeAndSet(JsonParser p, DeserializationContext ctxt,
Object bean, String key) throws IOException
{
final SettableBeanProperty prop = find(key);
if (prop == null) {
return false;
}
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, key, ctxt);
}
return true;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("Properties=[");
int count = 0;
Iterator<SettableBeanProperty> it = iterator();
while (it.hasNext()) {
SettableBeanProperty prop = it.next();
if (count++ > 0) {
sb.append(", ");
}
sb.append(prop.getName());
sb.append('(');
sb.append(prop.getType());
sb.append(')');
}
sb.append(']');
return sb.toString();
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
protected SettableBeanProperty _rename(SettableBeanProperty prop, NameTransformer xf)
{
if (prop == null) {
return prop;
}
String newName = xf.transform(prop.getName());
prop = prop.withSimpleName(newName);
JsonDeserializer<?> deser = prop.getValueDeserializer();
if (deser != null) {
@SuppressWarnings("unchecked")
JsonDeserializer<Object> newDeser = (JsonDeserializer<Object>)
deser.unwrappingDeserializer(xf);
if (newDeser != deser) {
prop = prop.withValueDeserializer(newDeser);
}
}
return prop;
}
protected void wrapAndThrow(Throwable t, Object bean, String fieldName, DeserializationContext ctxt)
throws IOException
{
// inlined 'throwOrReturnThrowable'
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors to be passed as is
if (t instanceof Error) {
throw (Error) t;
}
// StackOverflowErrors are tricky ones; need to be careful...
boolean wrap = (ctxt == null) || ctxt.isEnabled(DeserializationFeature.WRAP_EXCEPTIONS);
// Ditto for IOExceptions; except we may want to wrap JSON exceptions
if (t instanceof IOException) {
if (!wrap || !(t
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> instanceof JsonProcessingException)) {
throw (IOException) t;
}
} else if (!wrap) { // [JACKSON-407] -- allow disabling wrapping for unchecked exceptions
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
}
throw JsonMappingException.wrapWithPath(t, bean, fieldName);
}
/**
* Helper method used to find exact location of a property with name
* given exactly, not subject to case changes, within hash area.
* Expectation is that such property SHOULD exist, although no
* exception is thrown.
*
* @since 2.7
*/
private final int _findIndexInHash(String key)
{
final int slot = _hashCode(key);
int ix = (slot<<1);
// primary match?
if (key.equals(_hashArea[ix])) {
return ix+1;
}
// no? secondary?
int hashSize = _hashMask+1;
ix = hashSize + (slot>>1) << 1;
if (key.equals(_hashArea[ix])) {
return ix+1;
}
// perhaps spill then
int i = (hashSize + (hashSize>>1)) << 1;
for (int end = i + _spillCount; i < end; i += 2) {
if (key.equals(_hashArea[i])) {
return i+1;
}
}
return -1;
}
private final int _findFromOrdered(SettableBeanProperty prop) {
for (int i = 0, end = _propsInOrder.length; i < end; ++i) {
if (_propsInOrder[i] == prop) {
return i;
}
}
throw new IllegalStateException("Illegal state: property '"+prop.getName()+"' missing from _propsInOrder");
}
// Offlined version for convenience if we want to change hashing scheme
private final int _hashCode(String key) {
// This method produces better hash, fewer collisions... yet for some
// reason produces slightly worse performance. Very strange.
// 05-Aug-2015, tatu: ... still true?
/*
int h = key.hashCode();
return (h + (h >> 13)) & _hashMask;
*/
return key.hashCode() & _hashMask;
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JsonSerializable;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.util.RawValue;
/**
* Value node that contains a wrapped POJO, to be serialized as
* a JSON constructed through data mapping (usually done by
* calling {@link com.fasterxml.jackson.databind.ObjectMapper}).
*/
public class POJONode
extends ValueNode
{
protected final Object _value;
public POJONode(Object v) { _value = v; }
/*
/**********************************************************
/* Base class overrides
/**********************************************************
*/
@Override
public JsonNodeType getNodeType()
{
return JsonNodeType.POJO;
}
@Override public JsonToken asToken() { return JsonToken.VALUE_EMBEDDED_OBJECT; }
/**
* As it is possible that some implementations embed byte[] as POJONode
* (despite optimal being {@link BinaryNode}), let's add support for exposing
* binary data here too.
*/
@Override
public byte[] binaryValue() throws IOException
{
if (_value instanceof byte[]) {
return (byte[]) _value;
}
return super.binaryValue();
}
/*
/**********************************************************
/* General type coercions
/**********************************************************
*/
@Override
public String asText() { return (_value == null) ? "null" : _value.toString(); }
@Override public String asText(String defaultValue) {
return (_value == null) ? defaultValue : _value.toString();
}
@Override
public boolean asBoolean(boolean defaultValue)
{
if (_value != null && _value instanceof Boolean) {
return ((Boolean) _value).booleanValue();
}
return defaultValue;
}
@Override
public int asInt(int defaultValue)
{
if (_value instanceof Number) {
return ((Number) _value).intValue();
}
return defaultValue;
}
@Override
public long asLong(long defaultValue)
{
if (_value instanceof Number) {
return ((Number) _value).longValue();
}
return defaultValue;
}
@Override
public double asDouble(double defaultValue)
{
if (_value instanceof Number) {
return ((Number) _value).doubleValue();
}
return defaultValue;
}
/*
/**********************************************************
/* Public API, serialization
/**********************************************************
*/
@Override
public final void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException
{
if (_value == null) {
serializers.defaultSerializeNull(gen);
} else if (_value instanceof JsonSerializable) {
((JsonSerializable) _value).serialize(gen, serializers);
} else {
gen.writeObject(_value);
}
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Method that can be used to access the POJO this node wraps.
*/
public Object getPojo() { return _value; }
/*
/**********************************************************
/* Overridden standard methods
/**********************************************************
*/
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof POJONode) {
return _pojoEquals((POJONode)
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>: do NOT cache if polymorphic values, or ones with custom deserializer
return (_elementDeserializer == null) && (_elementTypeDeserializer == null);
}
/*
/**********************************************************
/* ContainerDeserializerBase API
/**********************************************************
*/
@Override
public JavaType getContentType() {
return _arrayType.getContentType();
}
@Override
public JsonDeserializer<Object> getContentDeserializer() {
return _elementDeserializer;
}
/*
/**********************************************************
/* JsonDeserializer API
/**********************************************************
*/
@Override
public Object[] deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
// Ok: must point to START_ARRAY (or equivalent)
if (!jp.isExpectedStartArrayToken()) {
return handleNonArray(jp, ctxt);
}
final ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] chunk = buffer.resetAndStart();
int ix = 0;
JsonToken t;
final TypeDeserializer typeDeser = _elementTypeDeserializer;
try {
while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
// Note: must handle null explicitly here; value deserializers won't
Object value;
if (t == JsonToken.VALUE_NULL) {
value = _elementDeserializer.getNullValue(ctxt);
} else if (typeDeser == null) {
value = _elementDeserializer.deserialize(jp, ctxt);
} else {
value = _elementDeserializer.deserializeWithType(jp, ctxt, typeDeser);
}
if (ix >= chunk.length) {
chunk = buffer.appendCompletedChunk(chunk);
ix = 0;
}
chunk[ix++] = value;
}
} catch (Exception e) {
throw JsonMappingException.wrapWithPath(e, chunk, buffer.bufferedSize() + ix);
}
Object[] result;
if (_untyped) {
result = buffer.completeAndClearBuffer(chunk, ix);
} else {
result = buffer.completeAndClearBuffer(chunk, ix, _elementClass);
}
ctxt.returnObjectBuffer(buffer);
return result;
}
@Override
public Object[] deserializeWithType(JsonParser jp, DeserializationContext ctxt,
TypeDeserializer typeDeserializer)
throws IOException, JsonProcessingException
{
/* Should there be separate handling for base64 stuff?
* for now this should be enough:
*/
return (Object[]) typeDeserializer.deserializeTypedFromArray(jp, ctxt);
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected Byte[] deserializeFromBase64(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
// First same as what PrimitiveArrayDeserializers.ByteDeser does:
byte[] b = jp.getBinaryValue(ctxt.getBase64Variant());
// But then need to convert to wrappers
Byte[] result = new Byte[b.length];
for (int i = 0, len = b.length; i < len; ++i) {
result[i] = Byte.valueOf(b[i]);
}
return result;
}
private final Object[] handleNonArray(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
// [JACKSON-620] Empty String can become null...
if ((jp.getCurrentToken() == JsonToken.VALUE_STRING)
&& ctxt.isEnabled(DeserializationFeature.
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
String str = jp.getText();
if (str.length() == 0) {
return null;
}
}
// Can we do implicit coercion to a single-element array still?
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)) {
/* 04-Oct-2009, tatu: One exception; byte arrays are generally
* serialized as base64, so that should be handled
*/
if (jp.getCurrentToken() == JsonToken.VALUE_STRING
&& _elementClass == Byte.class) {
return deserializeFromBase64(jp, ctxt);
}
throw ctxt.mappingException(_arrayType.getRawClass());
}
JsonToken t = jp.getCurrentToken();
Object value;
if (t == JsonToken.VALUE_NULL) {
value = _elementDeserializer.getNullValue(ctxt);
} else if (_elementTypeDeserializer == null) {
value = _elementDeserializer.deserialize(jp, ctxt);
} else {
value = _elementDeserializer.deserializeWithType(jp, ctxt, _elementTypeDeserializer);
}
// Ok: bit tricky, since we may want T[], not just Object[]
Object[] result;
if (_untyped) {
result = new Object[1];
} else {
result = (Object[]) Array.newInstance(_elementClass, 1);
}
result[0] = value;
return result;
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>
*/
/**
* Main deserialization method for bean-based objects (POJOs).
*<p>
* NOTE: was declared 'final' in 2.2; should NOT be to let extensions
* like Afterburner change definition.
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// common case first
if (p.isExpectedStartObjectToken()) {
if (_vanillaProcessing) {
return vanillaDeserialize(p, ctxt, p.nextToken());
}
// 23-Sep-2015, tatu: This is wrong at some many levels, but for now... it is
// what it is, including "expected behavior".
p.nextToken();
if (_objectIdReader != null) {
return deserializeWithObjectId(p, ctxt);
}
return deserializeFromObject(p, ctxt);
}
JsonToken t = p.getCurrentToken();
return _deserializeOther(p, ctxt, t);
}
protected final Object _deserializeOther(JsonParser p, DeserializationContext ctxt,
JsonToken t) throws IOException
{
// and then others, generally requiring use of @JsonCreator
switch (t) {
case VALUE_STRING:
return deserializeFromString(p, ctxt);
case VALUE_NUMBER_INT:
return deserializeFromNumber(p, ctxt);
case VALUE_NUMBER_FLOAT:
return deserializeFromDouble(p, ctxt);
case VALUE_EMBEDDED_OBJECT:
return deserializeFromEmbedded(p, ctxt);
case VALUE_TRUE:
case VALUE_FALSE:
return deserializeFromBoolean(p, ctxt);
case START_ARRAY:
// these only work if there's a (delegating) creator...
return deserializeFromArray(p, ctxt);
case FIELD_NAME:
case END_OBJECT: // added to resolve [JACKSON-319], possible related issues
if (_vanillaProcessing) {
return vanillaDeserialize(p, ctxt, t);
}
if (_objectIdReader != null) {
return deserializeWithObjectId(p, ctxt);
}
return deserializeFromObject(p, ctxt);
default:
throw ctxt.mappingException(handledType());
}
}
protected Object _missingToken(JsonParser p, DeserializationContext ctxt) throws IOException {
throw ctxt.endOfInputException(handledType());
}
/**
* Secondary deserialization method, called in cases where POJO
* instance is created as part of deserialization, potentially
* after collecting some or all of the properties to set.
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt, Object bean) throws IOException
{
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
if (_injectables != null) {
injectValues(ctxt, bean);
}
if (_unwrappedPropertyHandler != null) {
return deserializeWithUnwrapped(p, ctxt, bean);
}
if (_externalTypeIdHandler != null) {
return deserializeWithExternalTypeId(p, ctxt, bean);
}
String propName;
// 23-Mar-2010, tatu: In some cases, we start with full JSON object too...
if (p.isExpectedStartObjectToken()) {
propName = p.nextFieldName();
if (propName == null) {
return bean;
}
} else {
if (p.has
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>TokenId(JsonTokenId.ID_FIELD_NAME)) {
propName = p.getCurrentName();
} else {
return bean;
}
}
if (_needViewProcesing) {
Class<?> view = ctxt.getActiveView();
if (view != null) {
return deserializeWithView(p, ctxt, bean, view);
}
}
do {
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
handleUnknownVanilla(p, ctxt, bean, propName);
} while ((propName = p.nextFieldName()) != null);
return bean;
}
/*
/**********************************************************
/* Concrete deserialization methods
/**********************************************************
*/
/**
* Streamlined version that is only used when no "special"
* features are enabled.
*/
private final Object vanillaDeserialize(JsonParser p,
DeserializationContext ctxt, JsonToken t)
throws IOException
{
final Object bean = _valueInstantiator.createUsingDefault(ctxt);
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) {
String propName = p.getCurrentName();
do {
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
handleUnknownVanilla(p, ctxt, bean, propName);
} while ((propName = p.nextFieldName()) != null);
}
return bean;
}
/**
* General version used when handling needs more advanced features.
*/
@Override
public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) throws IOException
{
/* 09-Dec-2014, tatu: As per [#622], we need to allow Object Id references
* to come in as JSON Objects as well; but for now assume they will
* be simple, single-property references, which means that we can
* recognize them without having to buffer anything.
* Once again, if we must, we can do more complex handling with buffering,
* but let's only do that if and when that becomes necessary.
*/
if (_objectIdReader != null && _objectIdReader.maySerializeAsObject()) {
if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)
&& _objectIdReader.isValidReferencePropertyName(p.getCurrentName(), p)) {
return deserializeFromObjectId(p, ctxt);
}
}
if (_nonStandardCreation) {
if (_unwrappedPropertyHandler != null) {
return deserializeWithUnwrapped(p, ctxt);
}
if (_externalTypeIdHandler != null) {
return deserializeWithExternalTypeId(p, ctxt);
}
Object bean = deserializeFromObjectUsingNonDefault(p, ctxt);
if (_injectables != null) {
injectValues(ctxt, bean);
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> }
/* 27-May-2014, tatu: I don't think view processing would work
* at this point, so commenting it out; but leaving in place
* just in case I forgot something fundamental...
*/
/*
if (_needViewProcesing) {
Class<?> view = ctxt.getActiveView();
if (view != null) {
return deserializeWithView(p, ctxt, bean, view);
}
}
*/
return bean;
}
final Object bean = _valueInstantiator.createUsingDefault(ctxt);
// [databind#631]: Assign current value, to be accessible by custom deserializers
p.setCurrentValue(bean);
if (p.canReadObjectId()) {
Object id = p.getObjectId();
if (id != null) {
_handleTypedObjectId(p, ctxt, bean, id);
}
}
if (_injectables != null) {
injectValues(ctxt, bean);
}
if (_needViewProcesing) {
Class<?> view = ctxt.getActiveView();
if (view != null) {
return deserializeWithView(p, ctxt, bean, view);
}
}
if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) {
String propName = p.getCurrentName();
do {
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
handleUnknownVanilla(p, ctxt, bean, propName);
} while ((propName = p.nextFieldName()) != null);
}
return bean;
}
/**
* Method called to deserialize bean using "property-based creator":
* this means that a non-default constructor or factory method is
* called, and then possibly other setters. The trick is that
* values for creator method need to be buffered, first; and
* due to non-guaranteed ordering possibly some other properties
* as well.
*/
@Override
@SuppressWarnings("resource")
protected Object _deserializeUsingPropertyBased(final JsonParser p, final DeserializationContext ctxt)
throws IOException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
// 04-Jan-2010, tatu: May need to collect unknown properties for polymorphic cases
TokenBuffer unknown = null;
JsonToken t = p.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken(); // to point to value
// creator property?
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null) {
// Last creator property to set?
if (buffer.assignParameter(creatorProp,
_deserializeWithErrorWrapping(p, ctxt, creatorProp))) {
p.nextToken(); // to move to following FIELD_NAME/END_OBJECT
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapInstantiationProblem(e, ctxt);
bean = null; // never
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> gets here
}
if (bean == null) {
throw ctxt.instantiationException(_beanType.getRawClass(), "JSON Creator returned null");
}
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
// polymorphic?
if (bean.getClass() != _beanType.getRawClass()) {
return handlePolymorphic(p, ctxt, bean, unknown);
}
if (unknown != null) { // nope, just extra unknown stuff...
bean = handleUnknownProperties(ctxt, bean, unknown);
}
// or just clean?
return deserialize(p, ctxt, bean);
}
continue;
}
// Object Id property?
if (buffer.readIdProperty(propName)) {
continue;
}
// regular property? needs buffering
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
buffer.bufferProperty(prop, _deserializeWithErrorWrapping(p, ctxt, prop));
continue;
}
// As per [JACKSON-313], things marked as ignorable should not be
// passed to any setter
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt, handledType(), propName);
continue;
}
// "any property"?
if (_anySetter != null) {
try {
buffer.bufferAnyProperty(_anySetter, propName, _anySetter.deserialize(p, ctxt));
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
}
continue;
}
// Ok then, let's collect the whole field; name and value
if (unknown == null) {
unknown = new TokenBuffer(p, ctxt);
}
unknown.writeFieldName(propName);
unknown.copyCurrentStructure(p);
}
// We hit END_OBJECT, so:
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapInstantiationProblem(e, ctxt);
bean = null; // never gets here
}
if (unknown != null) {
// polymorphic?
if (bean.getClass() != _beanType.getRawClass()) {
return handlePolymorphic(null, ctxt, bean, unknown);
}
// no, just some extra unknown properties
return handleUnknownProperties(ctxt, bean, unknown);
}
return bean;
}
protected final Object _deserializeWithErrorWrapping(JsonParser p,
DeserializationContext ctxt, SettableBeanProperty prop)
throws IOException
{
try {
return prop.deserialize(p, ctxt);
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), prop.getName(), ctxt);
// never gets here, unless caller declines to throw an exception
return null;
}
}
/*
/**********************************************************
/* Deserializing when we have to consider an active View
/**********************************************************
*/
protected final Object deserializeWithView(JsonParser p, DeserializationContext ctxt,
Object bean, Class<?> activeView)
throws IOException
{
if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) {
String propName = p.getCurrentName();
do {
p.nextToken();
// TODO: 06-Jan-2
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>015, tatu: try streamlining call sequences here as well
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
if (!prop.visibleInView(activeView)) {
p.skipChildren();
continue;
}
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
handleUnknownVanilla(p, ctxt, bean, propName);
} while ((propName = p.nextFieldName()) != null);
}
return bean;
}
/*
/**********************************************************
/* Handling for cases where we have "unwrapped" values
/**********************************************************
*/
/**
* Method called when there are declared "unwrapped" properties
* which need special handling
*/
@SuppressWarnings("resource")
protected Object deserializeWithUnwrapped(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (_delegateDeserializer != null) {
return _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.deserialize(p, ctxt));
}
if (_propertyBasedCreator != null) {
return deserializeUsingPropertyBasedWithUnwrapped(p, ctxt);
}
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
final Object bean = _valueInstantiator.createUsingDefault(ctxt);
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
if (_injectables != null) {
injectValues(ctxt, bean);
}
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
String propName = p.hasTokenId(JsonTokenId.ID_FIELD_NAME) ? p.getCurrentName() : null;
for (; propName != null; propName = p.nextFieldName()) {
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
if (activeView != null && !prop.visibleInView(activeView)) {
p.skipChildren();
continue;
}
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
// ignorable things should be ignored
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt, bean, propName);
continue;
}
// but... others should be passed to unwrapped property deserializers
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(p);
// how about any setter? We'll get copies but...
if (_anySetter != null) {
try {
_anySetter.deserializeAndSet(p, ctxt, bean, propName);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
}
tokens.writeEndObject();
_unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
return bean;
}
@SuppressWarnings("resource")
protected Object deserializeWithUnwrapped(JsonParser p, DeserializationContext ctxt, Object bean)
throws IOException
{
JsonToken t = p.getCurrentToken();
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>
if (t == JsonToken.START_OBJECT) {
t = p.nextToken();
}
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
SettableBeanProperty prop = _beanProperties.find(propName);
p.nextToken();
if (prop != null) { // normal case
if (activeView != null && !prop.visibleInView(activeView)) {
p.skipChildren();
continue;
}
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt, bean, propName);
continue;
}
// but... others should be passed to unwrapped property deserializers
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(p);
// how about any setter? We'll get copies but...
if (_anySetter != null) {
_anySetter.deserializeAndSet(p, ctxt, bean, propName);
}
}
tokens.writeEndObject();
_unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
return bean;
}
@SuppressWarnings("resource")
protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p, DeserializationContext ctxt)
throws IOException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
JsonToken t = p.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken(); // to point to value
// creator property?
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null) {
// Last creator property to set?
if (buffer.assignParameter(creatorProp, _deserializeWithErrorWrapping(p, ctxt, creatorProp))) {
t = p.nextToken(); // to move to following FIELD_NAME/END_OBJECT
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapInstantiationProblem(e, ctxt);
continue; // never gets here
}
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
// if so, need to copy all remaining tokens into buffer
while (t == JsonToken.FIELD_NAME) {
p.nextToken(); // to skip name
tokens.copyCurrentStructure(p);
t = p.nextToken();
}
tokens.writeEndObject();
if (bean.getClass() != _beanType.getRawClass()) {
// !!! 08-Jul-2011, tatu: Could probably support; but for now
// it's too complicated, so bail out
tokens.close();
throw ctxt.mappingException("Can not create polymorphic instances with unwrapped values
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>");
}
return _unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
}
continue;
}
// Object Id property?
if (buffer.readIdProperty(propName)) {
continue;
}
// regular property? needs buffering
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
buffer.bufferProperty(prop, _deserializeWithErrorWrapping(p, ctxt, prop));
continue;
}
/* As per [JACKSON-313], things marked as ignorable should not be
* passed to any setter
*/
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt, handledType(), propName);
continue;
}
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(p);
// "any property"?
if (_anySetter != null) {
try {
buffer.bufferAnyProperty(_anySetter, propName, _anySetter.deserialize(p, ctxt));
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
}
}
}
// We hit END_OBJECT, so:
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapInstantiationProblem(e, ctxt);
return null; // never gets here
}
return _unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
}
/*
/**********************************************************
/* Handling for cases where we have property/-ies with
/* external type id
/**********************************************************
*/
protected Object deserializeWithExternalTypeId(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (_propertyBasedCreator != null) {
return deserializeUsingPropertyBasedWithExternalTypeId(p, ctxt);
}
if (_delegateDeserializer != null) {
/* 24-Nov-2015, tatu: Use of delegating creator needs to have precedence, and basically
* external type id handling just has to be ignored, as they would relate to target
* type and not delegate type. Whether this works as expected is another story, but
* there's no other way to really mix these conflicting features.
*/
return _valueInstantiator.createUsingDelegate(ctxt,
_delegateDeserializer.deserialize(p, ctxt));
}
return deserializeWithExternalTypeId(p, ctxt, _valueInstantiator.createUsingDefault(ctxt));
}
protected Object deserializeWithExternalTypeId(JsonParser p, DeserializationContext ctxt,
Object bean)
throws IOException
{
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
final ExternalTypeHandler ext = _externalTypeIdHandler.start();
for (JsonToken t = p.getCurrentToken(); t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
t = p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
// [JACKSON-831]: may have property AND be used as external type id:
if (t.isScalarValue()) {
ext.handleTypePropertyValue(p, ctxt, propName, bean);
}
if (activeView != null && !prop
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>.visibleInView(activeView)) {
p.skipChildren();
continue;
}
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
// ignorable things should be ignored
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt, bean, propName);
continue;
}
// but others are likely to be part of external type id thingy...
if (ext.handlePropertyValue(p, ctxt, propName, bean)) {
continue;
}
// if not, the usual fallback handling:
if (_anySetter != null) {
try {
_anySetter.deserializeAndSet(p, ctxt, bean, propName);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
// Unknown: let's call handler method
handleUnknownProperty(p, ctxt, bean, propName);
}
// and when we get this far, let's try finalizing the deal:
return ext.complete(p, ctxt, bean);
}
@SuppressWarnings("resource")
protected Object deserializeUsingPropertyBasedWithExternalTypeId(JsonParser p, DeserializationContext ctxt)
throws IOException
{
final ExternalTypeHandler ext = _externalTypeIdHandler.start();
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
JsonToken t = p.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken(); // to point to value
// creator property?
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null) {
// first: let's check to see if this might be part of value with external type id:
// 11-Sep-2015, tatu: Important; do NOT pass buffer as last arg, but null,
// since it is not the bean
if (ext.handlePropertyValue(p, ctxt, propName, null)) {
;
} else {
// Last creator property to set?
if (buffer.assignParameter(creatorProp, _deserializeWithErrorWrapping(p, ctxt, creatorProp))) {
t = p.nextToken(); // to move to following FIELD_NAME/END_OBJECT
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
continue; // never gets here
}
// if so, need to copy all remaining tokens into buffer
while (t == JsonToken.FIELD_NAME) {
p.nextToken(); // to skip name
tokens.copyCurrentStructure(p);
t = p.nextToken();
}
if (bean.getClass() != _beanType.getRawClass()) {
// !!! 08-Jul-2011, tatu: Could theoretically support; but for now
// it's too complicated, so bail out
throw ctxt.mappingException("Can not create polymorphic instances with unwrapped values");
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
/**
* Intermediate base class for limited number of scalar types
* that should never include type information. These are "native"
* types that are default mappings for corresponding JSON scalar
* types: {@link java.lang.String}, {@link java.lang.Integer},
* {@link java.lang.Double} and {@link java.lang.Boolean}.
*/
@SuppressWarnings("serial")
public abstract class NonTypedScalarSerializerBase<T>
extends StdScalarSerializer<T>
{
protected NonTypedScalarSerializerBase(Class<T> t) {
super(t);
}
protected NonTypedScalarSerializerBase(Class<?> t, boolean bogus) {
super(t, bogus);
}
@Override
public final void serializeWithType(T value, JsonGenerator jgen, SerializerProvider provider,
TypeSerializer typeSer) throws IOException
{
// no type info, just regular serialization
serialize(value, jgen, provider);
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> "typed" object, when value itself
* is serialized as a scalar JSON value (something other
* than Array or Object), regardless of Java type.
* Method needs to figure out intended
* polymorphic type, locate {@link JsonDeserializer} to use, and
* call it with JSON data to deserializer (which does not contain
* type information).
*/
public abstract Object deserializeTypedFromScalar(JsonParser jp, DeserializationContext ctxt) throws IOException;
/**
* Method called to let this type deserializer handle
* deserialization of "typed" object, when value itself
* may have been serialized using any kind of JSON value
* (Array, Object, scalar). Should only be called if JSON
* serialization is polymorphic (not Java type); for example when
* using JSON node representation, or "untyped" Java object
* (which may be Map, Collection, wrapper/primitive etc).
*/
public abstract Object deserializeTypedFromAny(JsonParser jp, DeserializationContext ctxt) throws IOException;
/*
/**********************************************************
/* Shared helper methods
/**********************************************************
*/
/**
* Helper method used to check if given parser might be pointing to
* a "natural" value, and one that would be acceptable as the
* result value (compatible with declared base type)
*/
public static Object deserializeIfNatural(JsonParser jp, DeserializationContext ctxt, JavaType baseType) throws IOException {
return deserializeIfNatural(jp, ctxt, baseType.getRawClass());
}
@SuppressWarnings("incomplete-switch")
public static Object deserializeIfNatural(JsonParser jp, DeserializationContext ctxt, Class<?> base) throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == null) {
return null;
}
switch (t) {
case VALUE_STRING:
if (base.isAssignableFrom(String.class)) {
return jp.getText();
}
break;
case VALUE_NUMBER_INT:
if (base.isAssignableFrom(Integer.class)) {
return jp.getIntValue();
}
break;
case VALUE_NUMBER_FLOAT:
if (base.isAssignableFrom(Double.class)) {
return Double.valueOf(jp.getDoubleValue());
}
break;
case VALUE_TRUE:
if (base.isAssignableFrom(Boolean.class)) {
return Boolean.TRUE;
}
break;
case VALUE_FALSE:
if (base.isAssignableFrom(Boolean.class)) {
return Boolean.FALSE;
}
break;
}
return null;
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> base._valueToUpdate;
_schema = base._schema;
_injectableValues = base._injectableValues;
_unwrapRoot = base._unwrapRoot;
_dataFormatReaders = base._dataFormatReaders;
_filter = filter;
}
/**
* Method that will return version information stored in and read from jar
* that contains this class.
*/
@Override
public Version version() {
return com.fasterxml.jackson.databind.cfg.PackageVersion.VERSION;
}
/*
/**********************************************************
/* Methods sub-classes MUST override, used for constructing
/* reader instances, (re)configuring parser instances
/* Added in 2.5
/**********************************************************
*/
/**
* Overridable factory method called by various "withXxx()" methods
*
* @since 2.5
*/
protected ObjectReader _new(ObjectReader base, JsonFactory f) {
return new ObjectReader(base, f);
}
/**
* Overridable factory method called by various "withXxx()" methods
*
* @since 2.5
*/
protected ObjectReader _new(ObjectReader base, DeserializationConfig config) {
return new ObjectReader(base, config);
}
/**
* Overridable factory method called by various "withXxx()" methods
*
* @since 2.5
*/
protected ObjectReader _new(ObjectReader base, DeserializationConfig config,
JavaType valueType, JsonDeserializer<Object> rootDeser, Object valueToUpdate,
FormatSchema schema, InjectableValues injectableValues,
DataFormatReaders dataFormatReaders) {
return new ObjectReader(base, config, valueType, rootDeser, valueToUpdate,
schema, injectableValues, dataFormatReaders);
}
/**
* Factory method used to create {@link MappingIterator} instances;
* either default, or custom subtype.
*
* @since 2.5
*/
protected <T> MappingIterator<T> _newIterator(JsonParser p, DeserializationContext ctxt,
JsonDeserializer<?> deser, boolean parserManaged)
{
return new MappingIterator<T>(_valueType, p, ctxt,
deser, parserManaged, _valueToUpdate);
}
/*
/**********************************************************
/* Methods sub-classes may choose to override, if customized
/* initialization is needed.
/**********************************************************
*/
/**
* NOTE: changed from static to non-static in 2.5; unfortunate but
* necessary change to support overridability
*/
protected JsonToken _initForReading(JsonParser p) throws IOException
{
if (_schema != null) {
p.setSchema(_schema);
}
_config.initialize(p); // since 2.5
/* First: must point to a token; if not pointing to one, advance.
* This occurs before first read from JsonParser, as well as
* after clearing of current token.
*/
JsonToken t = p.getCurrentToken();
if (t == null) { // and then we must get something...
t = p.nextToken();
if (t == null) {
// Throw mapping exception, since it's failure to map, not an actual parsing problem
throw JsonMappingException.from(p, "No content to map due to end-of-input");
}
}
return t;
}
/**
* Alternative to {@link #_initForReading(JsonParser)} used in cases where reading
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> * to data bind into specified type.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.5
*/
public ObjectReader forType(JavaType valueType)
{
if (valueType != null && valueType.equals(_valueType)) {
return this;
}
JsonDeserializer<Object> rootDeser = _prefetchRootDeserializer(valueType);
// type is stored here, no need to make a copy of config
DataFormatReaders det = _dataFormatReaders;
if (det != null) {
det = det.withType(valueType);
}
return _new(this, _config, valueType, rootDeser,
_valueToUpdate, _schema, _injectableValues, det);
}
/**
* Method for constructing a new reader instance that is configured
* to data bind into specified type.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.5
*/
public ObjectReader forType(Class<?> valueType) {
return forType(_config.constructType(valueType));
}
/**
* Method for constructing a new reader instance that is configured
* to data bind into specified type.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.5
*/
public ObjectReader forType(TypeReference<?> valueTypeRef) {
return forType(_config.getTypeFactory().constructType(valueTypeRef.getType()));
}
/**
* @deprecated since 2.5 Use {@link #forType(JavaType)} instead
*/
@Deprecated
public ObjectReader withType(JavaType valueType) {
return forType(valueType);
}
/**
* @deprecated since 2.5 Use {@link #forType(Class)} instead
*/
@Deprecated
public ObjectReader withType(Class<?> valueType) {
return forType(_config.constructType(valueType));
}
/**
* @deprecated since 2.5 Use {@link #forType(Class)} instead
*/
@Deprecated
public ObjectReader withType(java.lang.reflect.Type valueType) {
return forType(_config.getTypeFactory().constructType(valueType));
}
/**
* @deprecated since 2.5 Use {@link #forType(TypeReference)} instead
*/
@Deprecated
public ObjectReader withType(TypeReference<?> valueTypeRef) {
return forType(_config.getTypeFactory().constructType(valueTypeRef.getType()));
}
/**
* Method for constructing a new instance with configuration that
* updates passed Object (as root value), instead of constructing
* a new value.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*/
public ObjectReader withValueToUpdate(Object value)
{
if (value == _valueToUpdate) return this;
if (value == null) {
throw new IllegalArgumentException("cat not update null value");
}
JavaType t;
/* no real benefit from pre-fetching, as updating readers are much
* less likely to be reused, and value type may also be forced
* with a later chained call...
*/
if
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> (_valueType == null) {
t = _config.constructType(value.getClass());
} else {
t = _valueType;
}
return _new(this, _config, t, _rootDeserializer, value,
_schema, _injectableValues, _dataFormatReaders);
}
/**
* Method for constructing a new instance with configuration that
* uses specified View for filtering.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*/
public ObjectReader withView(Class<?> activeView) {
return _with(_config.withView(activeView));
}
public ObjectReader with(Locale l) {
return _with(_config.with(l));
}
public ObjectReader with(TimeZone tz) {
return _with(_config.with(tz));
}
public ObjectReader withHandler(DeserializationProblemHandler h) {
return _with(_config.withHandler(h));
}
public ObjectReader with(Base64Variant defaultBase64) {
return _with(_config.with(defaultBase64));
}
/**
* Fluent factory method for constructing a reader that will try to
* auto-detect underlying data format, using specified list of
* {@link JsonFactory} instances, and default {@link DataFormatReaders} settings
* (for customized {@link DataFormatReaders}, you can construct instance yourself).
* to construct appropriate {@link JsonParser} for actual parsing.
*<p>
* Note: since format detection only works with byte sources, it is possible to
* get a failure from some 'readValue()' methods. Also, if input can not be reliably
* (enough) detected as one of specified types, an exception will be thrown.
*<p>
* Note: not all {@link JsonFactory} types can be passed: specifically, ones that
* require "custom codec" (like XML factory) will not work. Instead, use
* method that takes {@link ObjectReader} instances instead of factories.
*
* @param readers Data formats accepted, in decreasing order of priority (that is,
* matches checked in listed order, first match wins)
*
* @return Newly configured writer instance
*
* @since 2.1
*/
public ObjectReader withFormatDetection(ObjectReader... readers) {
return withFormatDetection(new DataFormatReaders(readers));
}
/**
* Fluent factory method for constructing a reader that will try to
* auto-detect underlying data format, using specified
* {@link DataFormatReaders}.
*<p>
* NOTE: since format detection only works with byte sources, it is possible to
* get a failure from some 'readValue()' methods. Also, if input can not be reliably
* (enough) detected as one of specified types, an exception will be thrown.
*
* @param readers DataFormatReaders to use for detecting underlying format.
*
* @return Newly configured writer instance
*
* @since 2.1
*/
public ObjectReader withFormatDetection(DataFormatReaders readers) {
return _new(this, _config, _valueType, _rootDeserializer, _valueToUpdate,
_schema, _injectableValues, readers);
}
/**
* @since 2.3
*/
public ObjectReader with(ContextAttributes attrs) {
return _with(_config.with(attrs));
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> unwrapped sequence
* of elements written as JSON Arrays: to read such sequences, one
* has to use {@link #readValues(JsonParser)}, making sure parser
* points to the first token of the first element (i.e. the second
* <code>START_ARRAY</code> which is part of the first element).
*/
public <T> MappingIterator<T> readValues(InputStream src)
throws IOException, JsonProcessingException
{
if (_dataFormatReaders != null) {
return _detectBindAndReadValues(_dataFormatReaders.findFormat(src), false);
}
return _bindAndReadValues(_considerFilter(_parserFactory.createParser(src)));
}
/**
* Overloaded version of {@link #readValue(InputStream)}.
*/
@SuppressWarnings("resource")
public <T> MappingIterator<T> readValues(Reader src)
throws IOException, JsonProcessingException
{
if (_dataFormatReaders != null) {
_reportUndetectableSource(src);
}
JsonParser p = _considerFilter(_parserFactory.createParser(src));
_initForMultiRead(p);
p.nextToken();
DeserializationContext ctxt = createDeserializationContext(p);
return _newIterator(p, ctxt, _findRootDeserializer(ctxt), true);
}
/**
* Overloaded version of {@link #readValue(InputStream)}.
*
* @param json String that contains JSON content to parse
*/
@SuppressWarnings("resource")
public <T> MappingIterator<T> readValues(String json)
throws IOException, JsonProcessingException
{
if (_dataFormatReaders != null) {
_reportUndetectableSource(json);
}
JsonParser p = _considerFilter(_parserFactory.createParser(json));
_initForMultiRead(p);
p.nextToken();
DeserializationContext ctxt = createDeserializationContext(p);
return _newIterator(p, ctxt, _findRootDeserializer(ctxt), true);
}
/**
* Overloaded version of {@link #readValue(InputStream)}.
*/
public <T> MappingIterator<T> readValues(byte[] src, int offset, int length)
throws IOException, JsonProcessingException
{
if (_dataFormatReaders != null) {
return _detectBindAndReadValues(_dataFormatReaders.findFormat(src, offset, length), false);
}
return _bindAndReadValues(_considerFilter(_parserFactory.createParser(src)));
}
/**
* Overloaded version of {@link #readValue(InputStream)}.
*/
public final <T> MappingIterator<T> readValues(byte[] src)
throws IOException, JsonProcessingException {
return readValues(src, 0, src.length);
}
/**
* Overloaded version of {@link #readValue(InputStream)}.
*/
public <T> MappingIterator<T> readValues(File src)
throws IOException, JsonProcessingException
{
if (_dataFormatReaders != null) {
return _detectBindAndReadValues(
_dataFormatReaders.findFormat(_inputStream(src)), false);
}
return _bindAndReadValues(_considerFilter(_parserFactory.createParser(src)));
}
/**
* Overloaded version of {@link #readValue(InputStream)}.
*
* @param src URL to read to access JSON content to parse.
*/
public <T> MappingIterator<T> readValues(URL src)
throws IOException, JsonProcessingException
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>
{
if (_dataFormatReaders != null) {
return _detectBindAndReadValues(
_dataFormatReaders.findFormat(_inputStream(src)), true);
}
return _bindAndReadValues(_considerFilter(_parserFactory.createParser(src)));
}
/*
/**********************************************************
/* Implementation of rest of ObjectCodec methods
/**********************************************************
*/
@Override
public <T> T treeToValue(TreeNode n, Class<T> valueType) throws JsonProcessingException
{
try {
return readValue(treeAsTokens(n), valueType);
} catch (JsonProcessingException e) {
throw e;
} catch (IOException e) { // should not occur, no real i/o...
throw new IllegalArgumentException(e.getMessage(), e);
}
}
@Override
public void writeValue(JsonGenerator gen, Object value) throws IOException, JsonProcessingException {
throw new UnsupportedOperationException("Not implemented for ObjectReader");
}
/*
/**********************************************************
/* Helper methods, data-binding
/**********************************************************
*/
/**
* Actual implementation of value reading+binding operation.
*/
protected Object _bind(JsonParser p, Object valueToUpdate) throws IOException
{
/* First: may need to read the next token, to initialize state (either
* before first read from parser, or after previous token has been cleared)
*/
Object result;
JsonToken t = _initForReading(p);
if (t == JsonToken.VALUE_NULL) {
if (valueToUpdate == null) {
DeserializationContext ctxt = createDeserializationContext(p);
result = _findRootDeserializer(ctxt).getNullValue(ctxt);
} else {
result = valueToUpdate;
}
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
result = valueToUpdate;
} else { // pointing to event other than null
DeserializationContext ctxt = createDeserializationContext(p);
JsonDeserializer<Object> deser = _findRootDeserializer(ctxt);
if (_unwrapRoot) {
result = _unwrapAndDeserialize(p, ctxt, _valueType, deser);
} else {
if (valueToUpdate == null) {
result = deser.deserialize(p, ctxt);
} else {
deser.deserialize(p, ctxt, valueToUpdate);
result = valueToUpdate;
}
}
}
// Need to consume the token too
p.clearCurrentToken();
return result;
}
/**
* Consider filter when creating JsonParser.
*/
protected JsonParser _considerFilter(final JsonParser p) {
return _filter == null || FilteringParserDelegate.class.isInstance(p)
? p : new FilteringParserDelegate(p, _filter, false, false);
}
protected Object _bindAndClose(JsonParser p) throws IOException
{
try {
Object result;
JsonToken t = _initForReading(p);
if (t == JsonToken.VALUE_NULL) {
if (_valueToUpdate == null) {
DeserializationContext ctxt = createDeserializationContext(p);
result = _findRootDeserializer(ctxt).getNullValue(ctxt);
} else {
result = _valueToUpdate;
}
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
result = _valueToUpdate;
} else {
DeserializationContext ctxt = createDeserializationContext(p);
JsonDeserializer<Object> deser = _findRootDeserializer
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>(ctxt);
if (_unwrapRoot) {
result = _unwrapAndDeserialize(p, ctxt, _valueType, deser);
} else {
if (_valueToUpdate == null) {
result = deser.deserialize(p, ctxt);
} else {
deser.deserialize(p, ctxt, _valueToUpdate);
result = _valueToUpdate;
}
}
}
return result;
} finally {
try {
p.close();
} catch (IOException ioe) { }
}
}
protected JsonNode _bindAndCloseAsTree(JsonParser p) throws IOException {
try {
return _bindAsTree(p);
} finally {
try {
p.close();
} catch (IOException ioe) { }
}
}
protected JsonNode _bindAsTree(JsonParser p) throws IOException
{
JsonNode result;
JsonToken t = _initForReading(p);
if (t == JsonToken.VALUE_NULL || t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
result = NullNode.instance;
} else {
DeserializationContext ctxt = createDeserializationContext(p);
JsonDeserializer<Object> deser = _findTreeDeserializer(ctxt);
if (_unwrapRoot) {
result = (JsonNode) _unwrapAndDeserialize(p, ctxt, JSON_NODE_TYPE, deser);
} else {
result = (JsonNode) deser.deserialize(p, ctxt);
}
}
// Need to consume the token too
p.clearCurrentToken();
return result;
}
/**
* @since 2.1
*/
protected <T> MappingIterator<T> _bindAndReadValues(JsonParser p) throws IOException
{
_initForMultiRead(p);
p.nextToken();
DeserializationContext ctxt = createDeserializationContext(p);
return _newIterator(p, ctxt, _findRootDeserializer(ctxt), true);
}
protected Object _unwrapAndDeserialize(JsonParser p, DeserializationContext ctxt,
JavaType rootType, JsonDeserializer<Object> deser) throws IOException
{
PropertyName expRootName = _config.findRootName(rootType);
// 12-Jun-2015, tatu: Should try to support namespaces etc but...
String expSimpleName = expRootName.getSimpleName();
if (p.getCurrentToken() != JsonToken.START_OBJECT) {
throw JsonMappingException.from(p, "Current token not START_OBJECT (needed to unwrap root name '"
+expSimpleName+"'), but "+p.getCurrentToken());
}
if (p.nextToken() != JsonToken.FIELD_NAME) {
throw JsonMappingException.from(p, "Current token not FIELD_NAME (to contain expected root name '"
+expSimpleName+"'), but "+p.getCurrentToken());
}
String actualName = p.getCurrentName();
if (!expSimpleName.equals(actualName)) {
throw JsonMappingException.from(p, "Root name '"+actualName+"' does not match expected ('"
+expSimpleName+"') for type "+rootType);
}
// ok, then move to value itself....
p.nextToken();
Object result;
if (_valueToUpdate == null) {
result = deser.deserialize(p, ctxt);
} else {
deser.deserialize(p, ctxt, _valueToUpdate);
result = _valueToUpdate;
}
// and last, verify that we now get
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> matching END_OBJECT
if (p.nextToken() != JsonToken.END_OBJECT) {
throw JsonMappingException.from(p, "Current token not END_OBJECT (to match wrapper object with root name '"
+expSimpleName+"'), but "+p.getCurrentToken());
}
return result;
}
/*
/**********************************************************
/* Internal methods, format auto-detection
/**********************************************************
*/
@SuppressWarnings("resource")
protected Object _detectBindAndClose(byte[] src, int offset, int length) throws IOException
{
DataFormatReaders.Match match = _dataFormatReaders.findFormat(src, offset, length);
if (!match.hasMatch()) {
_reportUnkownFormat(_dataFormatReaders, match);
}
JsonParser p = match.createParserWithMatch();
return match.getReader()._bindAndClose(p);
}
@SuppressWarnings("resource")
protected Object _detectBindAndClose(DataFormatReaders.Match match, boolean forceClosing)
throws IOException
{
if (!match.hasMatch()) {
_reportUnkownFormat(_dataFormatReaders, match);
}
JsonParser p = match.createParserWithMatch();
// One more thing: we Own the input stream now; and while it's
// not super clean way to do it, we must ensure closure so:
if (forceClosing) {
p.enable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
}
// important: use matching ObjectReader (may not be 'this')
return match.getReader()._bindAndClose(p);
}
@SuppressWarnings("resource")
protected <T> MappingIterator<T> _detectBindAndReadValues(DataFormatReaders.Match match, boolean forceClosing)
throws IOException, JsonProcessingException
{
if (!match.hasMatch()) {
_reportUnkownFormat(_dataFormatReaders, match);
}
JsonParser p = match.createParserWithMatch();
// One more thing: we Own the input stream now; and while it's
// not super clean way to do it, we must ensure closure so:
if (forceClosing) {
p.enable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
}
// important: use matching ObjectReader (may not be 'this')
return match.getReader()._bindAndReadValues(p);
}
@SuppressWarnings("resource")
protected JsonNode _detectBindAndCloseAsTree(InputStream in) throws IOException
{
DataFormatReaders.Match match = _dataFormatReaders.findFormat(in);
if (!match.hasMatch()) {
_reportUnkownFormat(_dataFormatReaders, match);
}
JsonParser p = match.createParserWithMatch();
p.enable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
return match.getReader()._bindAndCloseAsTree(p);
}
/**
* Method called to indicate that format detection failed to detect format
* of given input
*/
protected void _reportUnkownFormat(DataFormatReaders detector, DataFormatReaders.Match match) throws JsonProcessingException
{
throw new JsonParseException("Can not detect format from input, does not look like any of detectable formats "
+detector.toString(),
JsonLocation.NA);
}
/*
/**********************************************************
/* Internal methods, other
/**********************************************************
*/
/**
* @since 2.2
*/
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> protected void _verifySchemaType(FormatSchema schema)
{
if (schema != null) {
if (!_parserFactory.canUseSchema(schema)) {
throw new IllegalArgumentException("Can not use FormatSchema of type "+schema.getClass().getName()
+" for format "+_parserFactory.getFormatName());
}
}
}
/**
* Internal helper method called to create an instance of {@link DeserializationContext}
* for deserializing a single root value.
* Can be overridden if a custom context is needed.
*/
protected DefaultDeserializationContext createDeserializationContext(JsonParser p) {
return _context.createInstance(_config, p, _injectableValues);
}
protected void _reportUndetectableSource(Object src) throws JsonProcessingException
{
throw new JsonParseException("Can not use source of type "
+src.getClass().getName()+" with format auto-detection: must be byte- not char-based",
JsonLocation.NA);
}
protected InputStream _inputStream(URL src) throws IOException {
return src.openStream();
}
protected InputStream _inputStream(File f) throws IOException {
return new FileInputStream(f);
}
/*
/**********************************************************
/* Helper methods, locating deserializers etc
/**********************************************************
*/
/**
* Method called to locate deserializer for the passed root-level value.
*/
protected JsonDeserializer<Object> _findRootDeserializer(DeserializationContext ctxt)
throws JsonMappingException
{
if (_rootDeserializer != null) {
return _rootDeserializer;
}
// Sanity check: must have actual type...
JavaType t = _valueType;
if (t == null) {
throw new JsonMappingException("No value type configured for ObjectReader");
}
// First: have we already seen it?
JsonDeserializer<Object> deser = _rootDeserializers.get(t);
if (deser != null) {
return deser;
}
// Nope: need to ask provider to resolve it
deser = ctxt.findRootValueDeserializer(t);
if (deser == null) { // can this happen?
throw new JsonMappingException("Can not find a deserializer for type "+t);
}
_rootDeserializers.put(t, deser);
return deser;
}
/**
* @since 2.6
*/
protected JsonDeserializer<Object> _findTreeDeserializer(DeserializationContext ctxt)
throws JsonMappingException
{
JsonDeserializer<Object> deser = _rootDeserializers.get(JSON_NODE_TYPE);
if (deser == null) {
// Nope: need to ask provider to resolve it
deser = ctxt.findRootValueDeserializer(JSON_NODE_TYPE);
if (deser == null) { // can this happen?
throw new JsonMappingException("Can not find a deserializer for type "+JSON_NODE_TYPE);
}
_rootDeserializers.put(JSON_NODE_TYPE, deser);
}
return deser;
}
/**
* Method called to locate deserializer ahead of time, if permitted
* by configuration. Method also is NOT to throw an exception if
* access fails.
*/
protected JsonDeserializer<Object> _prefetchRootDeserializer(JavaType valueType)
{
if (valueType == null || !_config.isEnabled(DeserializationFeature.EAGER_DESERIALIZER_FETCH)) {
return null;
}
// already cached?
JsonDeserializer<Object> deser = _rootDeserializers.get(valueType);
if
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>> _notNullClass(Class<?> cls) {
return (cls == null) ? Object.class : (Class<Object>) cls;
}
public JsonValueSerializer withResolved(BeanProperty property,
JsonSerializer<?> ser, boolean forceTypeInfo)
{
if (_property == property && _valueSerializer == ser
&& forceTypeInfo == _forceTypeInformation) {
return this;
}
return new JsonValueSerializer(this, property, ser, forceTypeInfo);
}
/*
/**********************************************************
/* Post-processing
/**********************************************************
*/
/**
* We can try to find the actual serializer for value, if we can
* statically figure out what the result type must be.
*/
@Override
public JsonSerializer<?> createContextual(SerializerProvider provider,
BeanProperty property)
throws JsonMappingException
{
JsonSerializer<?> ser = _valueSerializer;
if (ser == null) {
/* Can only assign serializer statically if the declared type is final:
* if not, we don't really know the actual type until we get the instance.
*/
// 10-Mar-2010, tatu: Except if static typing is to be used
if (provider.isEnabled(MapperFeature.USE_STATIC_TYPING)
|| Modifier.isFinal(_accessorMethod.getReturnType().getModifiers())) {
JavaType t = provider.constructType(_accessorMethod.getGenericReturnType());
// false -> no need to cache
/* 10-Mar-2010, tatu: Ideally we would actually separate out type
* serializer from value serializer; but, alas, there's no access
* to serializer factory at this point...
*/
// 05-Sep-2013, tatu: I _think_ this can be considered a primary property...
ser = provider.findPrimaryPropertySerializer(t, property);
/* 09-Dec-2010, tatu: Turns out we must add special handling for
* cases where "native" (aka "natural") type is being serialized,
* using standard serializer
*/
boolean forceTypeInformation = isNaturalTypeWithStdHandling(t.getRawClass(), ser);
return withResolved(property, ser, forceTypeInformation);
}
} else {
// 05-Sep-2013, tatu: I _think_ this can be considered a primary property...
ser = provider.handlePrimaryContextualization(ser, property);
return withResolved(property, ser, _forceTypeInformation);
}
return this;
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public void serialize(Object bean, JsonGenerator jgen, SerializerProvider prov) throws IOException
{
try {
Object value = _accessorMethod.invoke(bean);
if (value == null) {
prov.defaultSerializeNull(jgen);
return;
}
JsonSerializer<Object> ser = _valueSerializer;
if (ser == null) {
Class<?> c = value.getClass();
/* 10-Mar-2010, tatu: Ideally we would actually separate out type
* serializer from value serializer; but, alas, there's no access
* to serializer factory at this point...
*/
// let's cache it, may be needed soon again
ser = prov.findTypedValueSerializer(c, true, _property);
}
ser.serialize(value, jgen
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>, prov);
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
Throwable t = e;
// Need to unwrap this specific type, to see infinite recursion...
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors shouldn't be wrapped (and often can't, as well)
if (t instanceof Error) {
throw (Error) t;
}
// let's try to indicate the path best we can...
throw JsonMappingException.wrapWithPath(t, bean, _accessorMethod.getName() + "()");
}
}
@Override
public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvider provider,
TypeSerializer typeSer0) throws IOException
{
// Regardless of other parts, first need to find value to serialize:
Object value = null;
try {
value = _accessorMethod.invoke(bean);
// and if we got null, can also just write it directly
if (value == null) {
provider.defaultSerializeNull(jgen);
return;
}
JsonSerializer<Object> ser = _valueSerializer;
if (ser == null) { // already got a serializer? fabulous, that be easy...
// ser = provider.findTypedValueSerializer(value.getClass(), true, _property);
ser = provider.findValueSerializer(value.getClass(), _property);
} else {
/* 09-Dec-2010, tatu: To work around natural type's refusal to add type info, we do
* this (note: type is for the wrapper type, not enclosed value!)
*/
if (_forceTypeInformation) {
typeSer0.writeTypePrefixForScalar(bean, jgen);
ser.serialize(value, jgen, provider);
typeSer0.writeTypeSuffixForScalar(bean, jgen);
return;
}
}
/* 13-Feb-2013, tatu: Turns out that work-around should NOT be required
* at all; it would not lead to correct behavior (as per #167).
*/
// and then redirect type id lookups
// TypeSerializer typeSer = new TypeSerializerWrapper(typeSer0, bean);
ser.serializeWithType(value, jgen, provider, typeSer0);
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
Throwable t = e;
// Need to unwrap this specific type, to see infinite recursion...
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors shouldn't be wrapped (and often can't, as well)
if (t instanceof Error) {
throw (Error) t;
}
// let's try to indicate the path best we can...
throw JsonMappingException.wrapWithPath(t, bean, _accessorMethod.getName() + "()");
}
}
@SuppressWarnings("deprecation")
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
if (_valueSerializer instanceof SchemaAware) {
return ((SchemaAware)_valueSerializer).getSchema(provider, null);
}
return com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode();
}
@Override
public void acceptJsonFormatVisitor(
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
/* 27-Apr-2015, tatu: First things first; for JSON Schema introspection,
* Enums are special, and unfortunately we will need to add special
* handling here (see https://github.com/FasterXML/jackson-module-jsonSchema/issues/57
* for details).
*/
Class<?> decl = (typeHint == null) ? null : typeHint.getRawClass();
if (decl == null) {
decl = _accessorMethod.getDeclaringClass();
}
if ((decl != null) && (decl.isEnum())) {
if (_acceptJsonFormatVisitorForEnum(visitor, typeHint, decl)) {
return;
}
}
JsonSerializer<Object> ser = _valueSerializer;
if (ser == null) {
if (typeHint == null) {
if (_property != null) {
typeHint = _property.getType();
}
if (typeHint == null) {
typeHint = visitor.getProvider().constructType(_handledType);
}
}
ser = visitor.getProvider().findTypedValueSerializer(typeHint, false, _property);
if (ser == null) {
visitor.expectAnyFormat(typeHint);
return;
}
}
ser.acceptJsonFormatVisitor(visitor, null);
}
/**
* Overridable helper method used for special case handling of schema information for
* Enums
*
* @return True if method handled callbacks; false if not; in latter case caller will
* send default callbacks
*
* @since 2.6
*/
protected boolean _acceptJsonFormatVisitorForEnum(JsonFormatVisitorWrapper visitor,
JavaType typeHint, Class<?> enumType)
throws JsonMappingException
{
// Copied from EnumSerializer#acceptJsonFormatVisitor
JsonStringFormatVisitor stringVisitor = visitor.expectStringFormat(typeHint);
if (stringVisitor != null) {
Set<String> enums = new LinkedHashSet<String>();
for (Object en : enumType.getEnumConstants()) {
try {
enums.add(String.valueOf(_accessorMethod.invoke(en)));
} catch (Exception e) {
Throwable t = e;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error) {
throw (Error) t;
}
throw JsonMappingException.wrapWithPath(t, en, _accessorMethod.getName() + "()");
}
}
stringVisitor.enumTypes(enums);
}
return true;
}
protected boolean isNaturalTypeWithStdHandling(Class<?> rawType, JsonSerializer<?> ser)
{
// First: do we have a natural type being handled?
if (rawType.isPrimitive()) {
if (rawType != Integer.TYPE && rawType != Boolean.TYPE && rawType != Double.TYPE) {
return false;
}
} else {
if (rawType != String.class &&
rawType != Integer.class && rawType != Boolean.class && rawType != Double.class) {
return false;
}
}
return isDefaultSerializer(ser);
}
/*
/**********************************************************
/* Other methods
/**********************************************************
*/
@Override
public String toString() {
return "(@JsonValue serializer for method " + _accessorMethod.get
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>Context ctxt, boolean value) throws IOException
{
try {
if (_fromBooleanCreator != null) {
return _fromBooleanCreator.call1(Boolean.valueOf(value));
}
} catch (Exception e) {
throw wrapException(e);
} catch (ExceptionInInitializerError e) {
throw wrapException(e);
}
throw ctxt.mappingException("Can not instantiate value of type %s"
+" from Boolean value (%s); no single-boolean/Boolean-arg constructor/factory method",
getValueTypeDesc(), value);
}
/*
/**********************************************************
/* Extended API: configuration mutators, accessors
/**********************************************************
*/
@Override
public AnnotatedWithParams getDelegateCreator() {
return _delegateCreator;
}
@Override
public AnnotatedWithParams getDefaultCreator() {
return _defaultCreator;
}
@Override
public AnnotatedWithParams getWithArgsCreator() {
return _withArgsCreator;
}
@Override
public AnnotatedParameter getIncompleteParameter() {
return _incompleteParameter;
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected JsonMappingException wrapException(Throwable t)
{
while (t.getCause() != null) {
t = t.getCause();
}
if (t instanceof JsonMappingException) {
return (JsonMappingException) t;
}
return new JsonMappingException("Instantiation of "+getValueTypeDesc()+" value failed: "+t.getMessage(), t);
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import java.lang.annotation.Annotation;
import java.util.*;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.util.Converter;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Abstract class that defines API used for introspecting annotation-based
* configuration for serialization and deserialization. Separated
* so that different sets of annotations can be supported, and support
* plugged-in dynamically.
*<p>
* NOTE: due to rapid addition of new methods (and changes to existing methods),
* it is <b>strongly</b> recommended that custom implementations should not directly
* extend this class, but rather extend {@link NopAnnotationIntrospector}.
* This way added methods will not break backwards compatibility of custom annotation
* introspectors.
*/
@SuppressWarnings("serial")
public abstract class AnnotationIntrospector
implements Versioned, java.io.Serializable
{
/*
/**********************************************************
/* Helper types
/**********************************************************
*/
/**
* Value type used with managed and back references; contains type and
* logic name, used to link related references
*/
public static class ReferenceProperty
{
public enum Type {
/**
* Reference property that Jackson manages and that is serialized normally (by serializing
* reference object), but is used for resolving back references during
* deserialization.
* Usually this can be defined by using
* {@link com.fasterxml.jackson.annotation.JsonManagedReference}
*/
MANAGED_REFERENCE
/**
* Reference property that Jackson manages by suppressing it during serialization,
* and reconstructing during deserialization.
* Usually this can be defined by using
* {@link com.fasterxml.jackson.annotation.JsonBackReference}
*/
,BACK_REFERENCE
;
}
private final Type _type;
private final String _name;
public ReferenceProperty(Type t, String n) {
_type = t;
_name = n;
}
public static ReferenceProperty managed(String name) { return new ReferenceProperty(Type.MANAGED_REFERENCE, name); }
public static ReferenceProperty back(String name) { return new ReferenceProperty(Type.BACK_REFERENCE, name); }
public Type getType() { return _type; }
public String getName() { return _name; }
public boolean isManagedReference() { return _type == Type.MANAGED_REFERENCE
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.BeanDeserializer;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Deserializer that builds on basic {@link BeanDeserializer} but
* override some aspects like instance construction.
*/
public class ThrowableDeserializer
extends BeanDeserializer
{
private static final long serialVersionUID = 1L;
protected final static String PROP_NAME_MESSAGE = "message";
/*
/************************************************************
/* Construction
/************************************************************
*/
public ThrowableDeserializer(BeanDeserializer baseDeserializer) {
super(baseDeserializer);
// need to disable this, since we do post-processing
_vanillaProcessing = false;
}
/**
* Alternative constructor used when creating "unwrapping" deserializers
*/
protected ThrowableDeserializer(BeanDeserializer src, NameTransformer unwrapper) {
super(src, unwrapper);
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper) {
if (getClass() != ThrowableDeserializer.class) {
return this;
}
/* main thing really is to just enforce ignoring of unknown
* properties; since there may be multiple unwrapped values
* and properties for all may be interleaved...
*/
return new ThrowableDeserializer(this, unwrapper);
}
/*
/************************************************************
/* Overridden methods
/************************************************************
*/
@Override
public Object deserializeFromObject(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// 30-Sep-2010, tatu: Need to allow use of @JsonCreator, so:
if (_propertyBasedCreator != null) { // proper @JsonCreator
return _deserializeUsingPropertyBased(jp, ctxt);
}
if (_delegateDeserializer != null) {
return _valueInstantiator.createUsingDelegate(ctxt,
_delegateDeserializer.deserialize(jp, ctxt));
}
if (_beanType.isAbstract()) { // for good measure, check this too
throw JsonMappingException.from(jp, "Can not instantiate abstract type "+_beanType
+" (need to add/enable type information?)");
}
boolean hasStringCreator = _valueInstantiator.canCreateFromString();
boolean hasDefaultCtor = _valueInstantiator.canCreateUsingDefault();
// and finally, verify we do have single-String arg constructor (if no @JsonCreator)
if (!hasStringCreator && !hasDefaultCtor) {
throw new JsonMappingException("Can not deserialize Throwable of type "+_beanType
+" without having a default contructor, a single-String-arg constructor; or explicit @JsonCreator");
}
Object throwable = null;
Object[] pending = null;
int pendingIx = 0;
for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
String propName = jp.getCurrentName();
SettableBeanProperty prop = _beanProperties.find(propName);
jp.nextToken(); // to point to field value
if (prop != null) { // normal case
if (throwable != null) {
prop.deserializeAndSet(jp, ctxt, throwable);
continue;
}
// nope; need to defer
if (pending == null) {
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.util.RawValue;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
/**
* Node that maps to JSON Object structures in JSON content.
*<p>
* Note: class was <code>final</code> temporarily for Jackson 2.2.
*/
public class ObjectNode
extends ContainerNode<ObjectNode>
{
// Note: LinkedHashMap for backwards compatibility
protected final Map<String, JsonNode> _children;
public ObjectNode(JsonNodeFactory nc) {
super(nc);
_children = new LinkedHashMap<String, JsonNode>();
}
/**
* @since 2.4
*/
public ObjectNode(JsonNodeFactory nc, Map<String, JsonNode> kids) {
super(nc);
_children = kids;
}
@Override
protected JsonNode _at(JsonPointer ptr) {
return get(ptr.getMatchingProperty());
}
/* Question: should this delegate to `JsonNodeFactory`? It does not absolutely
* have to, as long as sub-types override the method but...
*/
// note: co-variant for type safety
@SuppressWarnings("unchecked")
@Override
public ObjectNode deepCopy()
{
ObjectNode ret = new ObjectNode(_nodeFactory);
for (Map.Entry<String, JsonNode> entry: _children.entrySet())
ret._children.put(entry.getKey(), entry.getValue().deepCopy());
return ret;
}
/*
/**********************************************************
/* Overrides for JsonSerializable.Base
/**********************************************************
*/
@Override
public boolean isEmpty(SerializerProvider serializers) {
return _children.isEmpty();
}
/*
/**********************************************************
/* Implementation of core JsonNode API
/**********************************************************
*/
@Override
public JsonNodeType getNodeType() {
return JsonNodeType.OBJECT;
}
@Override public JsonToken asToken() { return JsonToken.START_OBJECT; }
@Override
public int size() {
return _children.size();
}
@Override
public Iterator<JsonNode> elements() {
return _children.values().iterator();
}
@Override
public JsonNode get(int index) { return null; }
@Override
public JsonNode get(String fieldName) {
return _children.get(fieldName);
}
@Override
public Iterator<String> fieldNames() {
return _children.keySet().iterator();
}
@Override
public JsonNode path(int index) {
return MissingNode.getInstance();
}
@Override
public JsonNode path(String fieldName)
{
JsonNode n = _children.get(fieldName);
if (n != null) {
return n;
}
return MissingNode.getInstance();
}
/**
* Method to use for accessing all fields (with both names
* and values) of this JSON Object.
*/
@Override
public Iterator<Map.Entry<String, JsonNode>> fields() {
return _children.entrySet().iterator();
}
@Override
public ObjectNode with(String propertyName) {
JsonNode n = _children.get(propertyName);
if (n != null) {
if (n instanceof ObjectNode) {
return (ObjectNode) n;
}
throw new UnsupportedOperationException("
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.NumberOutput;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Numeric node that contains 64-bit ("double precision")
* floating point values simple 32-bit integer values.
*/
public class DoubleNode
extends NumericNode
{
protected final double _value;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
public DoubleNode(double v) { _value = v; }
public static DoubleNode valueOf(double v) { return new DoubleNode(v); }
/*
/**********************************************************
/* BaseJsonNode extended API
/**********************************************************
*/
@Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_FLOAT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.DOUBLE; }
/*
/**********************************************************
/* Overrridden JsonNode methods
/**********************************************************
*/
@Override
public boolean isFloatingPointNumber() { return true; }
@Override
public boolean isDouble() { return true; }
@Override public boolean canConvertToInt() {
return (_value >= Integer.MIN_VALUE && _value <= Integer.MAX_VALUE);
}
@Override public boolean canConvertToLong() {
return (_value >= Long.MIN_VALUE && _value <= Long.MAX_VALUE);
}
@Override
public Number numberValue() {
return Double.valueOf(_value);
}
@Override
public short shortValue() { return (short) _value; }
@Override
public int intValue() { return (int) _value; }
@Override
public long longValue() { return (long) _value; }
@Override
public float floatValue() { return (float) _value; }
@Override
public double doubleValue() { return _value; }
@Override
public BigDecimal decimalValue() { return BigDecimal.valueOf(_value); }
@Override
public BigInteger bigIntegerValue() {
return decimalValue().toBigInteger();
}
@Override
public String asText() {
return NumberOutput.toString(_value);
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.writeNumber(_value);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof DoubleNode) {
// We must account for NaNs: NaN does not equal NaN, therefore we have
// to use Double.compare().
final double otherValue = ((DoubleNode) o)._value;
return Double.compare(_value, otherValue) == 0;
}
return false;
}
@Override
public int hashCode()
{
// same as hashCode Double.class uses
long l = Double.doubleToLongBits(_value);
return ((int) l) ^ (int) (l >> 32);
}
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> for stream-based object
* conversion through parser/generator interfaces. If null,
* such methods can not be used.
*
* @return Parser that can be used for reading contents stored in this buffer
*/
public JsonParser asParser(ObjectCodec codec)
{
return new Parser(_first, codec, _hasNativeTypeIds, _hasNativeObjectIds);
}
/**
* @param src Parser to use for accessing source information
* like location, configured codec
*/
public JsonParser asParser(JsonParser src)
{
Parser p = new Parser(_first, src.getCodec(), _hasNativeTypeIds, _hasNativeObjectIds);
p.setLocation(src.getTokenLocation());
return p;
}
/*
/**********************************************************
/* Additional accessors
/**********************************************************
*/
public JsonToken firstToken() {
if (_first != null) {
return _first.type(0);
}
return null;
}
/*
/**********************************************************
/* Other custom methods not needed for implementing interfaces
/**********************************************************
*/
/**
* Helper method that will append contents of given buffer into this
* buffer.
* Not particularly optimized; can be made faster if there is need.
*
* @return This buffer
*/
@SuppressWarnings("resource")
public TokenBuffer append(TokenBuffer other) throws IOException
{
// Important? If source has native ids, need to store
if (!_hasNativeTypeIds) {
_hasNativeTypeIds = other.canWriteTypeId();
}
if (!_hasNativeObjectIds) {
_hasNativeObjectIds = other.canWriteObjectId();
}
_mayHaveNativeIds = _hasNativeTypeIds | _hasNativeObjectIds;
JsonParser p = other.asParser();
while (p.nextToken() != null) {
copyCurrentStructure(p);
}
return this;
}
/**
* Helper method that will write all contents of this buffer
* using given {@link JsonGenerator}.
*<p>
* Note: this method would be enough to implement
* <code>JsonSerializer</code> for <code>TokenBuffer</code> type;
* but we can not have upwards
* references (from core to mapper package); and as such we also
* can not take second argument.
*/
public void serialize(JsonGenerator gen) throws IOException
{
Segment segment = _first;
int ptr = -1;
final boolean checkIds = _mayHaveNativeIds;
boolean hasIds = checkIds && (segment.hasIds());
while (true) {
if (++ptr >= Segment.TOKENS_PER_SEGMENT) {
ptr = 0;
segment = segment.next();
if (segment == null) break;
hasIds = checkIds && (segment.hasIds());
}
JsonToken t = segment.type(ptr);
if (t == null) break;
if (hasIds) {
Object id = segment.findObjectId(ptr);
if (id != null) {
gen.writeObjectId(id);
}
id = segment.findTypeId(ptr);
if (id != null) {
gen.writeTypeId(id);
}
}
// Note: copied from 'copyCurrentEvent'...
switch (t) {
case START_OBJECT:
gen.writeStartObject();
break;
case END_OBJECT:
gen.writeEndObject();
break;
case START_ARRAY:
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>
gen.writeStartArray();
break;
case END_ARRAY:
gen.writeEndArray();
break;
case FIELD_NAME:
{
// 13-Dec-2010, tatu: Maybe we should start using different type tokens to reduce casting?
Object ob = segment.get(ptr);
if (ob instanceof SerializableString) {
gen.writeFieldName((SerializableString) ob);
} else {
gen.writeFieldName((String) ob);
}
}
break;
case VALUE_STRING:
{
Object ob = segment.get(ptr);
if (ob instanceof SerializableString) {
gen.writeString((SerializableString) ob);
} else {
gen.writeString((String) ob);
}
}
break;
case VALUE_NUMBER_INT:
{
Object n = segment.get(ptr);
if (n instanceof Integer) {
gen.writeNumber((Integer) n);
} else if (n instanceof BigInteger) {
gen.writeNumber((BigInteger) n);
} else if (n instanceof Long) {
gen.writeNumber((Long) n);
} else if (n instanceof Short) {
gen.writeNumber((Short) n);
} else {
gen.writeNumber(((Number) n).intValue());
}
}
break;
case VALUE_NUMBER_FLOAT:
{
Object n = segment.get(ptr);
if (n instanceof Double) {
gen.writeNumber(((Double) n).doubleValue());
} else if (n instanceof BigDecimal) {
gen.writeNumber((BigDecimal) n);
} else if (n instanceof Float) {
gen.writeNumber(((Float) n).floatValue());
} else if (n == null) {
gen.writeNull();
} else if (n instanceof String) {
gen.writeNumber((String) n);
} else {
throw new JsonGenerationException("Unrecognized value type for VALUE_NUMBER_FLOAT: "+n.getClass().getName()+", can not serialize");
}
}
break;
case VALUE_TRUE:
gen.writeBoolean(true);
break;
case VALUE_FALSE:
gen.writeBoolean(false);
break;
case VALUE_NULL:
gen.writeNull();
break;
case VALUE_EMBEDDED_OBJECT:
{
Object value = segment.get(ptr);
if (value instanceof RawValue) {
((RawValue) value).serialize(gen);
} else {
gen.writeObject(value);
}
}
break;
default:
throw new RuntimeException("Internal error: should never end up through this code path");
}
}
}
/**
* Helper method used by standard deserializer.
*
* @since 2.3
*/
public TokenBuffer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
if (p.getCurrentTokenId() != JsonToken.FIELD_NAME.id()) {
copyCurrentStructure(p);
return this;
}
/* 28-Oct-2014, tatu: As per [databind#592], need to support a special case of starting from
* FIELD_NAME, which is taken to mean that we are missing START_OBJECT, but need
* to assume one did exist.
*/
JsonToken t;
writeStartObject();
do {
copyCurrentStructure(p);
} while ((t = p.nextToken()) == JsonToken.
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>FIELD_NAME);
if (t != JsonToken.END_OBJECT) {
throw ctxt.mappingException("Expected END_OBJECT after copying contents of a JsonParser into TokenBuffer, got "+t);
}
writeEndObject();
return this;
}
@Override
@SuppressWarnings("resource")
public String toString()
{
// Let's print up to 100 first tokens...
final int MAX_COUNT = 100;
StringBuilder sb = new StringBuilder();
sb.append("[TokenBuffer: ");
/*
sb.append("NativeTypeIds=").append(_hasNativeTypeIds).append(",");
sb.append("NativeObjectIds=").append(_hasNativeObjectIds).append(",");
*/
JsonParser jp = asParser();
int count = 0;
final boolean hasNativeIds = _hasNativeTypeIds || _hasNativeObjectIds;
while (true) {
JsonToken t;
try {
t = jp.nextToken();
if (t == null) break;
if (hasNativeIds) {
_appendNativeIds(sb);
}
if (count < MAX_COUNT) {
if (count > 0) {
sb.append(", ");
}
sb.append(t.toString());
if (t == JsonToken.FIELD_NAME) {
sb.append('(');
sb.append(jp.getCurrentName());
sb.append(')');
}
}
} catch (IOException ioe) { // should never occur
throw new IllegalStateException(ioe);
}
++count;
}
if (count >= MAX_COUNT) {
sb.append(" ... (truncated ").append(count-MAX_COUNT).append(" entries)");
}
sb.append(']');
return sb.toString();
}
private final void _appendNativeIds(StringBuilder sb)
{
Object objectId = _last.findObjectId(_appendAt-1);
if (objectId != null) {
sb.append("[objectId=").append(String.valueOf(objectId)).append(']');
}
Object typeId = _last.findTypeId(_appendAt-1);
if (typeId != null) {
sb.append("[typeId=").append(String.valueOf(typeId)).append(']');
}
}
/*
/**********************************************************
/* JsonGenerator implementation: configuration
/**********************************************************
*/
@Override
public JsonGenerator enable(Feature f) {
_generatorFeatures |= f.getMask();
return this;
}
@Override
public JsonGenerator disable(Feature f) {
_generatorFeatures &= ~f.getMask();
return this;
}
//public JsonGenerator configure(SerializationFeature f, boolean state) { }
@Override
public boolean isEnabled(Feature f) {
return (_generatorFeatures & f.getMask()) != 0;
}
@Override
public int getFeatureMask() {
return _generatorFeatures;
}
@Override
public JsonGenerator setFeatureMask(int mask) {
_generatorFeatures = mask;
return this;
}
@Override
public JsonGenerator useDefaultPrettyPrinter() {
// No-op: we don't indent
return this;
}
@Override
public JsonGenerator setCodec(ObjectCodec oc) {
_objectCodec = oc;
return this;
}
@Override
public ObjectCodec getCodec() { return _objectCodec; }
@Override
public final JsonWriteContext getOutputContext() { return _writeContext;
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> }
/*
/**********************************************************
/* JsonGenerator implementation: capability introspection
/**********************************************************
*/
/**
* Since we can efficiently store <code>byte[]</code>, yes.
*/
@Override
public boolean canWriteBinaryNatively() {
return true;
}
/*
/**********************************************************
/* JsonGenerator implementation: low-level output handling
/**********************************************************
*/
@Override
public void flush() throws IOException { /* NOP */ }
@Override
public void close() throws IOException {
_closed = true;
}
@Override
public boolean isClosed() { return _closed; }
/*
/**********************************************************
/* JsonGenerator implementation: write methods, structural
/**********************************************************
*/
@Override
public final void writeStartArray() throws IOException
{
_append(JsonToken.START_ARRAY);
_writeContext = _writeContext.createChildArrayContext();
}
@Override
public final void writeEndArray() throws IOException
{
_append(JsonToken.END_ARRAY);
// Let's allow unbalanced tho... i.e. not run out of root level, ever
JsonWriteContext c = _writeContext.getParent();
if (c != null) {
_writeContext = c;
}
}
@Override
public final void writeStartObject() throws IOException
{
_append(JsonToken.START_OBJECT);
_writeContext = _writeContext.createChildObjectContext();
}
@Override
public final void writeEndObject() throws IOException
{
_append(JsonToken.END_OBJECT);
// Let's allow unbalanced tho... i.e. not run out of root level, ever
JsonWriteContext c = _writeContext.getParent();
if (c != null) {
_writeContext = c;
}
}
@Override
public final void writeFieldName(String name) throws IOException
{
_append(JsonToken.FIELD_NAME, name);
_writeContext.writeFieldName(name);
}
@Override
public void writeFieldName(SerializableString name) throws IOException
{
_append(JsonToken.FIELD_NAME, name);
_writeContext.writeFieldName(name.getValue());
}
/*
/**********************************************************
/* JsonGenerator implementation: write methods, textual
/**********************************************************
*/
@Override
public void writeString(String text) throws IOException {
if (text == null) {
writeNull();
} else {
_appendValue(JsonToken.VALUE_STRING, text);
}
}
@Override
public void writeString(char[] text, int offset, int len) throws IOException {
writeString(new String(text, offset, len));
}
@Override
public void writeString(SerializableString text) throws IOException {
if (text == null) {
writeNull();
} else {
_appendValue(JsonToken.VALUE_STRING, text);
}
}
@Override
public void writeRawUTF8String(byte[] text, int offset, int length) throws IOException
{
// could add support for buffering if we really want it...
_reportUnsupportedOperation();
}
@Override
public void writeUTF8String(byte[] text, int offset, int length) throws IOException
{
// could add support for buffering if we really want it...
_reportUnsupportedOperation();
}
@Override
public void writeRaw(String text) throws IOException {
_reportUnsupportedOperation();
}
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> @Override
public void writeRaw(String text, int offset, int len) throws IOException {
_reportUnsupportedOperation();
}
@Override
public void writeRaw(SerializableString text) throws IOException {
_reportUnsupportedOperation();
}
@Override
public void writeRaw(char[] text, int offset, int len) throws IOException {
_reportUnsupportedOperation();
}
@Override
public void writeRaw(char c) throws IOException {
_reportUnsupportedOperation();
}
@Override
public void writeRawValue(String text) throws IOException {
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, new RawValue(text));
}
@Override
public void writeRawValue(String text, int offset, int len) throws IOException {
if (offset > 0 || len != text.length()) {
text = text.substring(offset, offset+len);
}
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, new RawValue(text));
}
@Override
public void writeRawValue(char[] text, int offset, int len) throws IOException {
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, new String(text, offset, len));
}
/*
/**********************************************************
/* JsonGenerator implementation: write methods, primitive types
/**********************************************************
*/
@Override
public void writeNumber(short i) throws IOException {
_appendValue(JsonToken.VALUE_NUMBER_INT, Short.valueOf(i));
}
@Override
public void writeNumber(int i) throws IOException {
_appendValue(JsonToken.VALUE_NUMBER_INT, Integer.valueOf(i));
}
@Override
public void writeNumber(long l) throws IOException {
_appendValue(JsonToken.VALUE_NUMBER_INT, Long.valueOf(l));
}
@Override
public void writeNumber(double d) throws IOException {
_appendValue(JsonToken.VALUE_NUMBER_FLOAT, Double.valueOf(d));
}
@Override
public void writeNumber(float f) throws IOException {
_appendValue(JsonToken.VALUE_NUMBER_FLOAT, Float.valueOf(f));
}
@Override
public void writeNumber(BigDecimal dec) throws IOException {
if (dec == null) {
writeNull();
} else {
_appendValue(JsonToken.VALUE_NUMBER_FLOAT, dec);
}
}
@Override
public void writeNumber(BigInteger v) throws IOException {
if (v == null) {
writeNull();
} else {
_appendValue(JsonToken.VALUE_NUMBER_INT, v);
}
}
@Override
public void writeNumber(String encodedValue) throws IOException {
/* 03-Dec-2010, tatu: related to [JACKSON-423], should try to keep as numeric
* identity as long as possible
*/
_appendValue(JsonToken.VALUE_NUMBER_FLOAT, encodedValue);
}
@Override
public void writeBoolean(boolean state) throws IOException {
_appendValue(state ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE);
}
@Override
public void writeNull() throws IOException {
_appendValue(JsonToken.VALUE_NULL);
}
/*
/***********************************************************
/* JsonGenerator implementation: write methods for POJOs/trees
/***********************************************************
*/
@Override
public void writeObject(Object value) throws IOException
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>
{
if (value == null) {
writeNull();
return;
}
Class<?> raw = value.getClass();
if (raw == byte[].class || (value instanceof RawValue)) {
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, value);
return;
}
if (_objectCodec == null) {
/* 28-May-2014, tatu: Tricky choice here; if no codec, should we
* err out, or just embed? For now, do latter.
*/
// throw new JsonMappingException("No ObjectCodec configured for TokenBuffer, writeObject() called");
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, value);
} else {
_objectCodec.writeValue(this, value);
}
}
@Override
public void writeTree(TreeNode node) throws IOException
{
if (node == null) {
writeNull();
return;
}
if (_objectCodec == null) {
// as with 'writeObject()', is codec optional?
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, node);
} else {
_objectCodec.writeTree(this, node);
}
}
/*
/***********************************************************
/* JsonGenerator implementation; binary
/***********************************************************
*/
@Override
public void writeBinary(Base64Variant b64variant, byte[] data, int offset, int len) throws IOException
{
/* 31-Dec-2009, tatu: can do this using multiple alternatives; but for
* now, let's try to limit number of conversions.
* The only (?) tricky thing is that of whether to preserve variant,
* seems pointless, so let's not worry about it unless there's some
* compelling reason to.
*/
byte[] copy = new byte[len];
System.arraycopy(data, offset, copy, 0, len);
writeObject(copy);
}
/**
* Although we could support this method, it does not necessarily make
* sense: we can not make good use of streaming because buffer must
* hold all the data. Because of this, currently this will simply
* throw {@link UnsupportedOperationException}
*/
@Override
public int writeBinary(Base64Variant b64variant, InputStream data, int dataLength) {
throw new UnsupportedOperationException();
}
/*
/***********************************************************
/* JsonGenerator implementation: native ids
/***********************************************************
*/
@Override
public boolean canWriteTypeId() {
return _hasNativeTypeIds;
}
@Override
public boolean canWriteObjectId() {
return _hasNativeObjectIds;
}
@Override
public void writeTypeId(Object id) {
_typeId = id;
_hasNativeId = true;
}
@Override
public void writeObjectId(Object id) {
_objectId = id;
_hasNativeId = true;
}
/*
/**********************************************************
/* JsonGenerator implementation; pass-through copy
/**********************************************************
*/
@Override
public void copyCurrentEvent(JsonParser p) throws IOException
{
if (_mayHaveNativeIds) {
_checkNativeIds(p);
}
switch (p.getCurrentToken()) {
case START_OBJECT:
writeStartObject();
break;
case END_OBJECT:
writeEndObject();
break;
case START_ARRAY:
writeStartArray();
break;
case END
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>_ARRAY:
writeEndArray();
break;
case FIELD_NAME:
writeFieldName(p.getCurrentName());
break;
case VALUE_STRING:
if (p.hasTextCharacters()) {
writeString(p.getTextCharacters(), p.getTextOffset(), p.getTextLength());
} else {
writeString(p.getText());
}
break;
case VALUE_NUMBER_INT:
switch (p.getNumberType()) {
case INT:
writeNumber(p.getIntValue());
break;
case BIG_INTEGER:
writeNumber(p.getBigIntegerValue());
break;
default:
writeNumber(p.getLongValue());
}
break;
case VALUE_NUMBER_FLOAT:
if (_forceBigDecimal) {
/* 10-Oct-2015, tatu: Ideally we would first determine whether underlying
* number is already decoded into a number (in which case might as well
* access as number); or is still retained as text (in which case we
* should further defer decoding that may not need BigDecimal):
*/
writeNumber(p.getDecimalValue());
} else {
switch (p.getNumberType()) {
case BIG_DECIMAL:
writeNumber(p.getDecimalValue());
break;
case FLOAT:
writeNumber(p.getFloatValue());
break;
default:
writeNumber(p.getDoubleValue());
}
}
break;
case VALUE_TRUE:
writeBoolean(true);
break;
case VALUE_FALSE:
writeBoolean(false);
break;
case VALUE_NULL:
writeNull();
break;
case VALUE_EMBEDDED_OBJECT:
writeObject(p.getEmbeddedObject());
break;
default:
throw new RuntimeException("Internal error: should never end up through this code path");
}
}
@Override
public void copyCurrentStructure(JsonParser jp) throws IOException
{
JsonToken t = jp.getCurrentToken();
// Let's handle field-name separately first
if (t == JsonToken.FIELD_NAME) {
if (_mayHaveNativeIds) {
_checkNativeIds(jp);
}
writeFieldName(jp.getCurrentName());
t = jp.nextToken();
// fall-through to copy the associated value
}
if (_mayHaveNativeIds) {
_checkNativeIds(jp);
}
switch (t) {
case START_ARRAY:
writeStartArray();
while (jp.nextToken() != JsonToken.END_ARRAY) {
copyCurrentStructure(jp);
}
writeEndArray();
break;
case START_OBJECT:
writeStartObject();
while (jp.nextToken() != JsonToken.END_OBJECT) {
copyCurrentStructure(jp);
}
writeEndObject();
break;
default: // others are simple:
copyCurrentEvent(jp);
}
}
private final void _checkNativeIds(JsonParser jp) throws IOException
{
if ((_typeId = jp.getTypeId()) != null) {
_hasNativeId = true;
}
if ((_objectId = jp.getObjectId()) != null) {
_hasNativeId = true;
}
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected final void _append(JsonToken type)
{
Segment next = _hasNativeId
? _last.append(_appendAt, type, _objectId, _typeId)
:
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> _last.append(_appendAt, type);
if (next == null) {
++_appendAt;
} else {
_last = next;
_appendAt = 1; // since we added first at 0
}
}
protected final void _append(JsonToken type, Object value)
{
Segment next = _hasNativeId
? _last.append(_appendAt, type, value, _objectId, _typeId)
: _last.append(_appendAt, type, value);
if (next == null) {
++_appendAt;
} else {
_last = next;
_appendAt = 1;
}
}
/**
* Similar to {@link #_append(JsonToken)} but also updates context with
* knowledge that a scalar value was written
*
* @since 2.6.4
*/
protected final void _appendValue(JsonToken type)
{
_writeContext.writeValue();
Segment next = _hasNativeId
? _last.append(_appendAt, type, _objectId, _typeId)
: _last.append(_appendAt, type);
if (next == null) {
++_appendAt;
} else {
_last = next;
_appendAt = 1; // since we added first at 0
}
}
/**
* Similar to {@link #_append(JsonToken,Object)} but also updates context with
* knowledge that a scalar value was written
*
* @since 2.6.4
*/
protected final void _appendValue(JsonToken type, Object value)
{
_writeContext.writeValue();
Segment next = _hasNativeId
? _last.append(_appendAt, type, value, _objectId, _typeId)
: _last.append(_appendAt, type, value);
if (next == null) {
++_appendAt;
} else {
_last = next;
_appendAt = 1;
}
}
protected final void _appendRaw(int rawType, Object value)
{
Segment next = _hasNativeId
? _last.appendRaw(_appendAt, rawType, value, _objectId, _typeId)
: _last.appendRaw(_appendAt, rawType, value);
if (next == null) {
++_appendAt;
} else {
_last = next;
_appendAt = 1;
}
}
@Override
protected void _reportUnsupportedOperation() {
throw new UnsupportedOperationException("Called operation not supported for TokenBuffer");
}
/*
/**********************************************************
/* Supporting classes
/**********************************************************
*/
protected final static class Parser
extends ParserMinimalBase
{
/*
/**********************************************************
/* Configuration
/**********************************************************
*/
protected ObjectCodec _codec;
/**
* @since 2.3
*/
protected final boolean _hasNativeTypeIds;
/**
* @since 2.3
*/
protected final boolean _hasNativeObjectIds;
protected final boolean _hasNativeIds;
/*
/**********************************************************
/* Parsing state
/**********************************************************
*/
/**
* Currently active segment
*/
protected Segment _segment;
/**
* Pointer to current token within current segment
*/
protected int _segmentPtr;
/**
* Information about parser context, context in which
* the next token is to be parsed (root, array, object).
*/
protected JsonReadContext _
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>parsingContext;
protected boolean _closed;
protected transient ByteArrayBuilder _byteBuilder;
protected JsonLocation _location = null;
/*
/**********************************************************
/* Construction, init
/**********************************************************
*/
public Parser(Segment firstSeg, ObjectCodec codec,
boolean hasNativeTypeIds,
boolean hasNativeObjectIds)
{
super(0);
_segment = firstSeg;
_segmentPtr = -1; // not yet read
_codec = codec;
_parsingContext = JsonReadContext.createRootContext(null);
_hasNativeTypeIds = hasNativeTypeIds;
_hasNativeObjectIds = hasNativeObjectIds;
_hasNativeIds = (hasNativeTypeIds | hasNativeObjectIds);
}
public void setLocation(JsonLocation l) {
_location = l;
}
@Override
public ObjectCodec getCodec() { return _codec; }
@Override
public void setCodec(ObjectCodec c) { _codec = c; }
@Override
public Version version() {
return com.fasterxml.jackson.databind.cfg.PackageVersion.VERSION;
}
/*
/**********************************************************
/* Extended API beyond JsonParser
/**********************************************************
*/
public JsonToken peekNextToken() throws IOException
{
// closed? nothing more to peek, either
if (_closed) return null;
Segment seg = _segment;
int ptr = _segmentPtr+1;
if (ptr >= Segment.TOKENS_PER_SEGMENT) {
ptr = 0;
seg = (seg == null) ? null : seg.next();
}
return (seg == null) ? null : seg.type(ptr);
}
/*
/**********************************************************
/* Closeable implementation
/**********************************************************
*/
@Override
public void close() throws IOException {
if (!_closed) {
_closed = true;
}
}
/*
/**********************************************************
/* Public API, traversal
/**********************************************************
*/
@Override
public JsonToken nextToken() throws IOException
{
// If we are closed, nothing more to do
if (_closed || (_segment == null)) return null;
// Ok, then: any more tokens?
if (++_segmentPtr >= Segment.TOKENS_PER_SEGMENT) {
_segmentPtr = 0;
_segment = _segment.next();
if (_segment == null) {
return null;
}
}
_currToken = _segment.type(_segmentPtr);
// Field name? Need to update context
if (_currToken == JsonToken.FIELD_NAME) {
Object ob = _currentObject();
String name = (ob instanceof String) ? ((String) ob) : ob.toString();
_parsingContext.setCurrentName(name);
} else if (_currToken == JsonToken.START_OBJECT) {
_parsingContext = _parsingContext.createChildObjectContext(-1, -1);
} else if (_currToken == JsonToken.START_ARRAY) {
_parsingContext = _parsingContext.createChildArrayContext(-1, -1);
} else if (_currToken == JsonToken.END_OBJECT
|| _currToken == JsonToken.END_ARRAY) {
// Closing JSON Object/Array? Close matching context
_parsingContext = _parsingContext.getParent();
// but allow unbalanced cases too (more close markers)
if (_parsingContext == null) {
_parsingContext = JsonReadContext.createRootContext(null);
}
}
return _
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>currToken;
}
@Override
public String nextFieldName() throws IOException
{
// inlined common case from nextToken()
if (_closed || (_segment == null)) return null;
int ptr = _segmentPtr+1;
if (ptr < Segment.TOKENS_PER_SEGMENT && _segment.type(ptr) == JsonToken.FIELD_NAME) {
_segmentPtr = ptr;
Object ob = _segment.get(ptr); // inlined _currentObject();
String name = (ob instanceof String) ? ((String) ob) : ob.toString();
_parsingContext.setCurrentName(name);
return name;
}
return (nextToken() == JsonToken.FIELD_NAME) ? getCurrentName() : null;
}
@Override
public boolean isClosed() { return _closed; }
/*
/**********************************************************
/* Public API, token accessors
/**********************************************************
*/
@Override
public JsonStreamContext getParsingContext() { return _parsingContext; }
@Override
public JsonLocation getTokenLocation() { return getCurrentLocation(); }
@Override
public JsonLocation getCurrentLocation() {
return (_location == null) ? JsonLocation.NA : _location;
}
@Override
public String getCurrentName() {
// 25-Jun-2015, tatu: as per [databind#838], needs to be same as ParserBase
if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) {
JsonReadContext parent = _parsingContext.getParent();
return parent.getCurrentName();
}
return _parsingContext.getCurrentName();
}
@Override
public void overrideCurrentName(String name)
{
// Simple, but need to look for START_OBJECT/ARRAY's "off-by-one" thing:
JsonReadContext ctxt = _parsingContext;
if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) {
ctxt = ctxt.getParent();
}
try {
ctxt.setCurrentName(name);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/*
/**********************************************************
/* Public API, access to token information, text
/**********************************************************
*/
@Override
public String getText()
{
// common cases first:
if (_currToken == JsonToken.VALUE_STRING
|| _currToken == JsonToken.FIELD_NAME) {
Object ob = _currentObject();
if (ob instanceof String) {
return (String) ob;
}
return (ob == null) ? null : ob.toString();
}
if (_currToken == null) {
return null;
}
switch (_currToken) {
case VALUE_NUMBER_INT:
case VALUE_NUMBER_FLOAT:
Object ob = _currentObject();
return (ob == null) ? null : ob.toString();
default:
return _currToken.asString();
}
}
@Override
public char[] getTextCharacters() {
String str = getText();
return (str == null) ? null : str.toCharArray();
}
@Override
public int getTextLength() {
String str = getText();
return (str == null) ? 0 : str.length();
}
@Override
public int getTextOffset() { return 0; }
@Override
public boolean hasTextCharacters() {
// We never have raw buffer available, so:
return false;
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>
}
/*
/**********************************************************
/* Public API, access to token information, numeric
/**********************************************************
*/
@Override
public BigInteger getBigIntegerValue() throws IOException
{
Number n = getNumberValue();
if (n instanceof BigInteger) {
return (BigInteger) n;
}
if (getNumberType() == NumberType.BIG_DECIMAL) {
return ((BigDecimal) n).toBigInteger();
}
// int/long is simple, but let's also just truncate float/double:
return BigInteger.valueOf(n.longValue());
}
@Override
public BigDecimal getDecimalValue() throws IOException
{
Number n = getNumberValue();
if (n instanceof BigDecimal) {
return (BigDecimal) n;
}
switch (getNumberType()) {
case INT:
case LONG:
return BigDecimal.valueOf(n.longValue());
case BIG_INTEGER:
return new BigDecimal((BigInteger) n);
default:
}
// float or double
return BigDecimal.valueOf(n.doubleValue());
}
@Override
public double getDoubleValue() throws IOException {
return getNumberValue().doubleValue();
}
@Override
public float getFloatValue() throws IOException {
return getNumberValue().floatValue();
}
@Override
public int getIntValue() throws IOException
{
// optimize common case:
if (_currToken == JsonToken.VALUE_NUMBER_INT) {
return ((Number) _currentObject()).intValue();
}
return getNumberValue().intValue();
}
@Override
public long getLongValue() throws IOException {
return getNumberValue().longValue();
}
@Override
public NumberType getNumberType() throws IOException
{
Number n = getNumberValue();
if (n instanceof Integer) return NumberType.INT;
if (n instanceof Long) return NumberType.LONG;
if (n instanceof Double) return NumberType.DOUBLE;
if (n instanceof BigDecimal) return NumberType.BIG_DECIMAL;
if (n instanceof BigInteger) return NumberType.BIG_INTEGER;
if (n instanceof Float) return NumberType.FLOAT;
if (n instanceof Short) return NumberType.INT; // should be SHORT
return null;
}
@Override
public final Number getNumberValue() throws IOException {
_checkIsNumber();
Object value = _currentObject();
if (value instanceof Number) {
return (Number) value;
}
// Difficult to really support numbers-as-Strings; but let's try.
// NOTE: no access to DeserializationConfig, unfortunately, so can not
// try to determine Double/BigDecimal preference...
if (value instanceof String) {
String str = (String) value;
if (str.indexOf('.') >= 0) {
return Double.parseDouble(str);
}
return Long.parseLong(str);
}
if (value == null) {
return null;
}
throw new IllegalStateException("Internal error: entry should be a Number, but is of type "
+value.getClass().getName());
}
/*
/**********************************************************
/* Public API, access to token information, other
/**********************************************************
*/
@Override
public Object getEmbeddedObject()
{
if (_currToken == JsonToken.VALUE_EMBEDDED_OBJECT) {
return _currentObject();
}
return null;
}
@Override
@SuppressWarnings("resource")
public byte[] getBinaryValue(Base64Variant b64variant) throws IOException, JsonParseException
{
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS>
// First: maybe we some special types?
if (_currToken == JsonToken.VALUE_EMBEDDED_OBJECT) {
// Embedded byte array would work nicely...
Object ob = _currentObject();
if (ob instanceof byte[]) {
return (byte[]) ob;
}
// fall through to error case
}
if (_currToken != JsonToken.VALUE_STRING) {
throw _constructError("Current token ("+_currToken+") not VALUE_STRING (or VALUE_EMBEDDED_OBJECT with byte[]), can not access as binary");
}
final String str = getText();
if (str == null) {
return null;
}
ByteArrayBuilder builder = _byteBuilder;
if (builder == null) {
_byteBuilder = builder = new ByteArrayBuilder(100);
} else {
_byteBuilder.reset();
}
_decodeBase64(str, builder, b64variant);
return builder.toByteArray();
}
@Override
public int readBinaryValue(Base64Variant b64variant, OutputStream out) throws IOException
{
byte[] data = getBinaryValue(b64variant);
if (data != null) {
out.write(data, 0, data.length);
return data.length;
}
return 0;
}
/*
/**********************************************************
/* Public API, native ids
/**********************************************************
*/
@Override
public boolean canReadObjectId() {
return _hasNativeObjectIds;
}
@Override
public boolean canReadTypeId() {
return _hasNativeTypeIds;
}
@Override
public Object getTypeId() {
return _segment.findTypeId(_segmentPtr);
}
@Override
public Object getObjectId() {
return _segment.findObjectId(_segmentPtr);
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected final Object _currentObject() {
return _segment.get(_segmentPtr);
}
protected final void _checkIsNumber() throws JsonParseException
{
if (_currToken == null || !_currToken.isNumeric()) {
throw _constructError("Current token ("+_currToken+") not numeric, can not use numeric value accessors");
}
}
@Override
protected void _handleEOF() throws JsonParseException {
_throwInternal();
}
}
/**
* Individual segment of TokenBuffer that can store up to 16 tokens
* (limited by 4 bits per token type marker requirement).
* Current implementation uses fixed length array; could alternatively
* use 16 distinct fields and switch statement (slightly more efficient
* storage, slightly slower access)
*/
protected final static class Segment
{
public final static int TOKENS_PER_SEGMENT = 16;
/**
* Static array used for fast conversion between token markers and
* matching {@link JsonToken} instances
*/
private final static JsonToken[] TOKEN_TYPES_BY_INDEX;
static {
// ... here we know that there are <= 15 values in JsonToken enum
TOKEN_TYPES_BY_INDEX = new JsonToken[16];
JsonToken[] t = JsonToken.values();
// and reserve entry 0 for "not available"
System.arraycopy(t, 1, TOKEN_TYPES_BY_INDEX, 1, Math.min(15, t.length - 1));
}
// // // Linking
protected Segment _next;
// //
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> // State
/**
* Bit field used to store types of buffered tokens; 4 bits per token.
* Value 0 is reserved for "not in use"
*/
protected long _tokenTypes;
// Actual tokens
protected final Object[] _tokens = new Object[TOKENS_PER_SEGMENT];
/**
* Lazily constructed Map for storing native type and object ids, if any
*/
protected TreeMap<Integer,Object> _nativeIds;
public Segment() { }
// // // Accessors
public JsonToken type(int index)
{
long l = _tokenTypes;
if (index > 0) {
l >>= (index << 2);
}
int ix = ((int) l) & 0xF;
return TOKEN_TYPES_BY_INDEX[ix];
}
public int rawType(int index)
{
long l = _tokenTypes;
if (index > 0) {
l >>= (index << 2);
}
int ix = ((int) l) & 0xF;
return ix;
}
public Object get(int index) {
return _tokens[index];
}
public Segment next() { return _next; }
/**
* Accessor for checking whether this segment may have native
* type or object ids.
*/
public boolean hasIds() {
return _nativeIds != null;
}
// // // Mutators
public Segment append(int index, JsonToken tokenType)
{
if (index < TOKENS_PER_SEGMENT) {
set(index, tokenType);
return null;
}
_next = new Segment();
_next.set(0, tokenType);
return _next;
}
public Segment append(int index, JsonToken tokenType,
Object objectId, Object typeId)
{
if (index < TOKENS_PER_SEGMENT) {
set(index, tokenType, objectId, typeId);
return null;
}
_next = new Segment();
_next.set(0, tokenType, objectId, typeId);
return _next;
}
public Segment append(int index, JsonToken tokenType, Object value)
{
if (index < TOKENS_PER_SEGMENT) {
set(index, tokenType, value);
return null;
}
_next = new Segment();
_next.set(0, tokenType, value);
return _next;
}
public Segment append(int index, JsonToken tokenType, Object value,
Object objectId, Object typeId)
{
if (index < TOKENS_PER_SEGMENT) {
set(index, tokenType, value, objectId, typeId);
return null;
}
_next = new Segment();
_next.set(0, tokenType, value, objectId, typeId);
return _next;
}
public Segment appendRaw(int index, int rawTokenType, Object value)
{
if (index < TOKENS_PER_SEGMENT) {
set(index, rawTokenType, value);
return null;
}
_next = new Segment();
_next.set(0, rawTokenType, value);
return _next;
}
public Segment appendRaw(int index, int rawTokenType, Object value,
Object objectId, Object typeId)
{
if (index < TOKENS_PER_SEGMENT) {
set(index, rawTokenType, value, objectId,
JacksonDatabind, 39
<FILEB>
<CHANGES>
if (p.hasToken(JsonToken.FIELD_NAME)) {
while (true) {
JsonToken t = p.nextToken();
if ((t == null) || (t == JsonToken.END_OBJECT)) {
break;
}
p.skipChildren();
}
} else {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
* @since 2.2
*/
public class NullifyingDeserializer
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static NullifyingDeserializer instance = new NullifyingDeserializer();
public NullifyingDeserializer() { super(Object.class); }
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 29-Jan-2016, tatu: Simple skipping for all other tokens, but FIELD_NAME bit
// special unfortunately
<CHANGES>
<CHANGEE>
p.skipChildren();
<CHANGES>
<CHANGEE>
return null;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
// Not sure if we need to bother but:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
<FILEE>
<SCANS> typeId);
return null;
}
_next = new Segment();
_next.set(0, rawTokenType, value, objectId, typeId);
return _next;
}
private void set(int index, JsonToken tokenType)
{
/* Assumption here is that there are no overwrites, just appends;
* and so no masking is needed (nor explicit setting of null)
*/
long typeCode = tokenType.ordinal();
if (index > 0) {
typeCode <<= (index << 2);
}
_tokenTypes |= typeCode;
}
private void set(int index, JsonToken tokenType,
Object objectId, Object typeId)
{
long typeCode = tokenType.ordinal();
if (index > 0) {
typeCode <<= (index << 2);
}
_tokenTypes |= typeCode;
assignNativeIds(index, objectId, typeId);
}
private void set(int index, JsonToken tokenType, Object value)
{
_tokens[index] = value;
long typeCode = tokenType.ordinal();
if (index > 0) {
typeCode <<= (index << 2);
}
_tokenTypes |= typeCode;
}
private void set(int index, JsonToken tokenType, Object value,
Object objectId, Object typeId)
{
_tokens[index] = value;
long typeCode = tokenType.ordinal();
if (index > 0) {
typeCode <<= (index << 2);
}
_tokenTypes |= typeCode;
assignNativeIds(index, objectId, typeId);
}
private void set(int index, int rawTokenType, Object value)
{
_tokens[index] = value;
long typeCode = (long) rawTokenType;
if (index > 0) {
typeCode <<= (index << 2);
}
_tokenTypes |= typeCode;
}
private void set(int index, int rawTokenType, Object value, Object objectId, Object typeId)
{
_tokens[index] = value;
long typeCode = (long) rawTokenType;
if (index > 0) {
typeCode <<= (index << 2);
}
_tokenTypes |= typeCode;
assignNativeIds(index, objectId, typeId);
}
private final void assignNativeIds(int index, Object objectId, Object typeId)
{
if (_nativeIds == null) {
_nativeIds = new TreeMap<Integer,Object>();
}
if (objectId != null) {
_nativeIds.put(_objectIdIndex(index), objectId);
}
if (typeId != null) {
_nativeIds.put(_typeIdIndex(index), typeId);
}
}
/**
* @since 2.3
*/
public Object findObjectId(int index) {
return (_nativeIds == null) ? null : _nativeIds.get(_objectIdIndex(index));
}
/**
* @since 2.3
*/
public Object findTypeId(int index) {
return (_nativeIds == null) ? null : _nativeIds.get(_typeIdIndex(index));
}
private final int _typeIdIndex(int i) { return i+i; }
private final int _objectIdIndex(int i) { return i+i+1; }
}
}